1👍
Assuming that fields in the model form for MyUser
are exactly similar to fields of your special user types, you can do something like this
def save(self, *args, **kwargs):
if self.fields['role'] == 'researcher'
return ResearchUser.objects.get_or_create( **self.fields)
....
else: # if none of above
super(MyUserForm, self).save(*args, **kwargs)
Note: you may want to use something better than .get_or_create()
, which will do look up for existing objects on all fields provided. But it may not find one and try to create new.
Refer the docs for exact behavior.
Source:stackexchange.com