我正在以下列方式使用模型:
class UserProfile:
# Some Stuff
class CompanyProfile(UserProfile):
# Some more stuff
class CandidateProfile(UserProfile):
# Even more stuff
表示CompanyProfile和CandidateProfile继承自UserProfile。如何从registrationform和另一个profileform填充这些CompanyProfile和CandidateProfile?我如何告诉我创建用户或输入数据的配置文件?
答案 0 :(得分:0)
我是按照以下方式在stackoverflow.com上的另一个线程中完成的:django user profile creation,set user profile while using multiple profile types,代码如下:
def save(self, commit=True):
user = super(UserRegistrationForm, self).save(commit=False)
user.email = self.cleaned_data["email"]
if commit:
user.save()
person = Person(user=user)
person.full_name = self.cleaned_data["fullname"]
person.save()
return user