Reputation: 76929
As I've understood the deal, the standard way of extending the User
Django model is by implementing profiles
.
This suits me wonderfully, since I have 3 types of profiles (3 different Model
subclasses) all based upon the User
model for uniqueness and authentication.
I'm having trouble deciding, however, on the best way of implementing a user creation form. Should I...
Use mixins: inherit a ModelForm
with model=User
and one with model=Profile
, manually overriding save()
and clean()
to call the bases' methods and perform the foreign key assignment.
Use composition: inherit Form
and manually instantiate and manage two ModelForms
.
Instantiate the forms separately, and save()
them in a manually ordered fashion.
The Best Way I Didn't Think Of.
I would appreciate a (however minimal) implementation so I can be sure I'm making the right calls.
Thanks in advance.
Upvotes: 0
Views: 408
Reputation: 48902
You can write a single form that acts as a combined ModelForm for both your Profile model and the contrib User model. To accomplish this, a little manipulation of the forms kwargs on init is required. See this snippet: http://djangosnippets.org/snippets/2081/
Upvotes: 1