我在 django 中扩展了 User 模型以包含其他几个变量,例如位置和雇主。现在我正在尝试创建一个包含以下字段的表单:
First name (from User)
Last name (from User)
Location (from UserProfile, which extends User via a foreign key)
Employer (also from UserProfile)
我创建了一个模型:
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
所以,我的问题是,如何创建一个可以访问所有字段的 ModelForm,无论它们来自 User 模型还是 UserProfile 模型?
希望这是有道理的。如果有任何问题,我会很乐意澄清。