django - How to create a ManyToManyField with choices -
i trying create django (2.7.3) models.manytomanyfield
allows user select multiple options form multiplechoicefield
having little trouble. idea user can select multiple elections intend vote in.
currently when run syncdb no errors , when visit page question partially displayed default title , no question options.
i have been looking around online , here on not sure missing. appriciated
models.py
class person(models.model): election = models.manytomanyfield('elections') def __unicode__(self): return self class elections(models.model): election_type = ( ('none', 'none'), ('local', 'local elections'), ('state', 'state elections e.g. governorship'), ('national', 'national elections e.g. congress , senate'), ('presidential', 'presidential elections'), ('other', 'other'), ('dont_know', "don't know"),) election_type = models.charfield(null=true, max_length=100, default=none, choices=election_type, verbose_name = 'which elections regularly vote in or intend vote in? select apply.') def __unicode__(self): return self
forms.py
class surveyformd(forms.modelform): # political viewpoints class meta: model = person fields = ['liberal_conservative', 'democrat_republican', 'voting_rights', 'elections'] widgets = {'liberal_conservative' : forms.radioselect, 'democrat_republican' : forms.radioselect, 'voting_rights' : forms.radioselect, 'elections' : forms.checkboxselectmultiple,}
Comments
Post a Comment