Monday, September 26, 2016

Modelform with reverse foreignkey

I am trying to create a ModelForm for movie Model from which it must be possible to select a number of theatre for each movie.Since theatre is reverse foreignkey i think ModelForm doesn't automatically  saves theatre values to the database.i tried to override the save method and ended up with the error.

Exception Type:ValueError
Exception Value:
save() prohibited to prevent data loss due to unsaved related object 'movie'.

Anyone please help me to solve this and thanks in advance.

class movieAdminForm(forms.ModelForm):

theatre = forms.ModelMultipleChoiceField(queryset=theatre.objects.all(),

class Meta:
model = movie
fields = ('image', 'image2', 'title', 'language', 'director', 'cast', 'y_tube_url',
'synopsis', 'like', 'music', 'cast',
'duration', 'genre', 'date', 'rating', 'writer','theatre')

def save(self,*args,**kwargs):
for i in self.cleaned_data['theatre']:

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment