[Answer]-Save in two or more models at the same time with form_valid

1👍

Add a method to your FormPropietario form :

class FormPropietario(forms.Form):

    ...

    def save_relateds(self):    
        admin = Administrador.objects.get_or_create(**self.cleaned_data)
        enc = Encargado.objects.get_or_create(**self.cleaned_data)
        return True

And then call it :

def form_valid(self, form):
    form.save_relateds()
    return super(PEPropietarioView,self).form_valid(form)

Leave a comment