请您一直在尝试以表格形式显示表格,但我无法做到。请克隆并创建数据库并在 github 上运行该项目。代码太多,无法粘贴到这里。
github:https ://github.com/mattisbmx/django-multipleChoiceField
模型:
from django.db import models
from multiselect.fields import ManyToManyField
class Choice(models.Model):
choice = models.CharField(max_length=15)
def __unicode__(self):
return self.choice
class SampleModel(models.Model):
name = models.CharField(max_length=15)
funciones = ManyToManyField(Choice)
passwd = models.TextField()
def __unicode__(self):
return unicode(self.pk)
看法:
def index(request):
data = {'form': forms.SelectForm()}
return render_to_response("multiselect/index.html", data,
context_instance=RequestContext(request
形式:
class SelectForm(forms.Form):
data = (('1', 'One'), ('2', 'Two'), ('3', 'Three'), ('4', 'Four')) #<--I think here I load the data model
choices = MultipleChoiceField(choices=data)
谢谢