0

Is there some way to update two or more models at the same time with UpdateView? For example having this:

class PEEncargadoView(UpdateModelMixin,UpdateView):
    model = Encargado
    form_class = FormEncargado
    success_url = '/'
    template_name = 'productores/PE/encargado.html'

Update other models besides of Encargado but in this same view

I know that this could be possible overriding get_context_data, but exactly how? if I don't need to pass any variables to the template.

dfrojas
  • 673
  • 1
  • 13
  • 32

1 Answers1

0

you can't do it with UpdateModelMixin - it's designed for working with a single model.

This question shows how to work with multiple forms in CBV: Django: Can class-based views accept two forms at a time?.

Django has formsets https://docs.djangoproject.com/en/1.8/topics/forms/formsets/ which can be used together with ModelForm to allow edition of multiple models on one page.

Community
  • 1
  • 1
jacekbj
  • 631
  • 3
  • 10
  • Thanks, but I dont need to render two forms in one template. Exactly Im looking for a solution for this http://stackoverflow.com/questions/30282885/update-in-three-models-at-the-same-time-in-form-valid-django?noredirect=1#comment48668678_30282885 – dfrojas May 17 '15 at 20:42