i have checkbox choice field this:
models.py type_choices = ( ('s', 'small'), ('m', 'medium'), ('b', 'big'), ) class post(models.model) : size = models.charfield(blank=true,max_length="3", choices=type_choices)
so in admin form:
class maincontent(forms.modelform): size = forms.multiplechoicefield(choices=type_choices, widget=forms.checkboxselectmultiple()) class meta: model = post fields = '__all__'
but when saving form give me error:
select valid choice. ['s', 'm', 'b'] not 1 of available choices.
so, problem?
update
my apology, question not given enough info, let me explain more.
the reason want checkbox input because want able store multiple values in single field (one column). perhaps data can serialized (or comma separated),
since type_choices static , not changed in future, not planning use manytomany.
also want able display in template language language.
hope clear enough.
presumably, want single column in table storing multiple values. force think how serialize - example, can't comma separated if need store strings might contain commas.
however, best using solution 1 of following:
this answer solve problem, try store list of strings, charfield.
or try use choicefield
Comments
Post a Comment