Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django multiple choice model problems

I have two diferents problems with multple choices in models.

The first, i'm trying to do a multiple choice so the user can pick one or more days of the week:

DAYS_CHOICES = (
    (1, _('Monday')),
    ...
    (7, _('Sunday')),
)
...
day = models.ManyToManyField('day', choices=DAYS_CHOICES)

The second problem:

I want to make a ManyToMany Relation with a model define in other model: First (Import to the model):

from events.models import Category

Second (The field related to the model):

type = models.ManyToManyField('Category', null=True, blank=True)

I get this error on syncdb:

Error: One or more models did not validate: situ.situ: 'day' has an m2m relation with model day, which has either not been installed or is abstract.
situ.situ: 'type' has an m2m relation with model Category, which has either not been installed or is abstract.

like image 568
JMira Avatar asked Dec 22 '22 17:12

JMira


1 Answers

you could use :

day = forms.ModelMultipleChoiceField(queryset=Day.objects.all())
like image 101
Muhammed Avatar answered Jan 03 '23 19:01

Muhammed