Sunday, 15 April 2012

How to get multiple choices in Django without using ManyToManyField? -



How to get multiple choices in Django without using ManyToManyField? -

i need create field can have multiple choices selected instead of one. these choices fixed. example:

we utilize charfield choices alternative if want 1 selection selected multiple ones.

sex_choices = (('m', 'male'), ('f', 'female') ) class model1(models.model): name = models.charfield(max_length=30) sex = models.charfield(max_length=1, choices=sex_choices)

but need similar setup multiple choice. don't want utilize manytomanyfield choices fixed , not changing time goes by.

please guide.

you have 3 basic choices:

to utilize djangozone has suggested in answer. add boolean field each choice. choices won't change. if don't change, why utilize method allows them to? gives lot of advantages on method #1, ie can index selection fields. use many many field. don't want don't why.

if don't change, i'd go #2. having bunch of booleanfields representation of set of choices don't change.

django django-models

No comments:

Post a Comment