2👍
As Berislav Lopac says:
class CategoryView(UpdateView):
model=Category
def form_valid(self, form):
self.object = form.save(commit=False)
IntermediateModel.objects.filter(category = self.object).delete()
for other_side_model_object in form.cleaned_data['other_side_model_field']:
intermediate_model = IntermediateModel()
intermediate_model.category = self.object
intermediate_model.other_side_model_related_field= other_side_model_object
intermediate_model.save()
return super(ModelFormMixin, self).form_valid(form)
I answer some similar here.
0👍
You should extend UpdateView
and override the form_valid()
method to manually save the intermediary model.
Personally, I never use generic views directly from the URL pattern, I always extend them verbatim in views.py
.
- [Answered ]-Can I bulk upload a CSV to Django with many to one relationship mapping?
- [Answered ]-What is safe implementation for sensitive data file file_url in Django
- [Answered ]-Django: How to filter patients from one department?
- [Answered ]-Using cache in django -how to create keys
Source:stackexchange.com