2012-04-07 60 views
0

繼承模型我使用模型方式如下:填充多表在Django

class UserProfile: 
# Some Stuff 

class CompanyProfile(UserProfile): 
# Some more stuff 

class CandidateProfile(UserProfile): 
# Even more stuff 

意味着公司簡介和CandidateProfile從用戶配置繼承。我將如何從這些CompanyProfile和CandidateProfile填充registrationform和另一個profileform?我將如何告訴它我正在創建一個用戶或輸入數據的哪個配置文件?

+0

你有沒有想出解決辦法? – Adam 2012-06-02 04:04:46

+0

@亞當是的,這個問題比較老,現在已經算出來了,會在幾個小時後在這裏發佈答案 – Hafiz 2012-06-03 09:50:00

回答

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