You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any way to use ManytoMany model relations to create inline connected forms? I did achieve using the foreign key but didn't find anything about ManytoMany, if it is not implemented how can I do it manually?
classQLevelInline(LoginRequiredMixin, InlineFormSetFactory):
model=QLevelform_class=questionLevelFormfactory_kwargs= {'extra': 1, 'max_num': None,
'can_order': False, 'can_delete': False}
classQuestionCreateView(LoginRequiredMixin, CreateWithInlinesView):
model=Questionform_class=questionForminlines= [QLevelInline, QSubjectInline, QMethodInline]
#other methods are also there but did not include due to simplicitydefforms_valid(self, form, inlines):
form.instance.author=self.request.userself.object=form.save()
forinlineininlines:
inline.save()
returnsuper().form_valid(form)
defget_success_url(self):
returnself.object.get_absolute_url()
Basically it works if I use the fk connected version, but I get error
ValueError at /question/new/
'file.QLevel' has no ForeignKey to 'file.Question'.
The text was updated successfully, but these errors were encountered:
Is there any way to use ManytoMany model relations to create inline connected forms? I did achieve using the foreign key but didn't find anything about ManytoMany, if it is not implemented how can I do it manually?
i.e.
models.py
views.py
Basically it works if I use the fk connected version, but I get error
The text was updated successfully, but these errors were encountered: