As described in my comment on the Django Trac ticket, I made a metaclass and mixin to allow multiple inheritance for Django ModelForm forms. With this, you can simply create a form that allows you to simultaneously register fields from user models and profiles without hardcoded fields or repeat yourself. Using my metaclass and mixin (as well as mixset mixin), you can:
class UserRegistrationForm(metaforms.FieldsetFormMixin, metaforms.ParentsIncludedModelFormMixin, UserCreationForm, UserProfileChangeForm): error_css_class = 'error' required_css_class = 'required' fieldset = UserCreationForm.fieldset + [( utils_text.capfirst(UserProfileChangeForm.Meta.model._meta.verbose_name), { 'fields': UserProfileChangeForm.base_fields.keys(), })] def save(self, commit=True):
Where UserCreationForm can be, for example, the form django.contrib.auth.forms.UserCreationForm and UserProfileChangeForm simple ModelForm for your profile model. (Remember to set editable to False in your foreign key for the User model.)
With a django registration database having this registration method:
def register(self, request, **kwargs): user = super(ProfileBackend, self).register(request, **kwargs) profile, created = utils.get_profile_model().objects.get_or_create(user=user)
Be careful that the registration signal is sent at the beginning of this method (in the method in the superclass), and not at the end.
In the same way, you can make a change form for both user information and the profile. An example of this can be found in my comment on the Django Trac ticket mentioned above.
Mitar Jul 21 '10 at 11:01 2010-07-21 11:01
source share