After extending the User model in django, how do you create a ModelForm?
Posted
by mlissner
on Stack Overflow
See other posts from Stack Overflow
or by mlissner
Published on 2010-03-24T22:06:50Z
Indexed on
2010/03/24
22:13 UTC
Read the original article
Hit count: 371
I extended the User model in django to include several other variables, such as location, and employer. Now I'm trying to create a form that has the following fields:
First name (from User)
Last name (from User)
Location (from UserProfile, which extends User via a foreign key)
Employer (also from UserProfile)
I have created a modelform:
from django.forms import ModelForm
from django.contrib import auth
from alert.userHandling.models import UserProfile
class ProfileForm(ModelForm):
class Meta:
# model = auth.models.User # this gives me the User fields
model = UserProfile # this gives me the UserProfile fields
So, my question is, how can I create a ModelForm that has access to all of the fields, whether they are from the User model or the UserProfile model?
Hope this makes sense. I'll be happy to clarify if there are any questions.
© Stack Overflow or respective owner