【问题标题】:populating multi-table inherited models in django在 django 中填充多表继承模型
【发布时间】:2012-04-20 22:41:32
【问题描述】:

我正在通过以下方式使用模型:

class UserProfile:
# Some Stuff

class CompanyProfile(UserProfile):
# Some more stuff

class CandidateProfile(UserProfile):
# Even more stuff

mean CompanyProfile 和 CandidateProfile 继承自 UserProfile 。我将如何从注册表和另一个配置文件中填充这些 CompanyProfile 和 CandidateProfile?我将如何告诉它我正在创建用户或输入数据的配置文件?

【问题讨论】:

  • 你有想过这个吗?
  • @Adam 是的,这个问题比较老,现在已经弄清楚了,几个小时后会在这里发布答案

标签: django django-models django-users django-profiles


【解决方案1】:

我在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-09
    • 2013-12-24
    • 2011-03-11
    • 1970-01-01
    • 2012-09-20
    • 2011-12-31
    • 1970-01-01
    相关资源
    最近更新 更多