djangodjango-modelsdjango-usersdjango-profiles

populating multi-table inherited models in django


I am using models in following way:

class UserProfile:
# Some Stuff

class CompanyProfile(UserProfile):
# Some more stuff

class CandidateProfile(UserProfile):
# Even more stuff

mean CompanyProfile and CandidateProfile are inheriting from UserProfile . How will I populate these CompanyProfile and CandidateProfile from whether registrationform and from another profileform? How will I tell it that which profile I am creating a user or entering data?


Solution

  • I did it in following way that is in another thread on stackoverflow.com here : django user profile creation,set user profile while using multiple profile types , code is following:

    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