I am trying to make several profiles for Userena - each user can have only one type of profile. After other discussions, I use multiple table inheritance, but when I do this, I canβt get the data to save into derived models. It all ends up being a CommonProfile, which should not be possible / allowed. Code example:
in models.py
:
# models.py # This is an example of how i've attempted to get # multiple user profiles working with Userena from django.contrib.auth.models import User from django.db import models from userena.models import UserenaLanguageBaseProfile class CommonProfile(UserenaLanguageBaseProfile): """Common fields for 2 user profiles: Spam and Eggs""" user = models.OneToOneField(User) common_field = models.CharField(max_length=100) @property def is_spam(self): """Find out if this is a Spam user""" try: self.spamprofile return True except SpamProfile.DoesNotExist: return False def get_real_type(self): """return the real model""" if self.is_spam: return self.spamprofile else: return self.eggsprofile class SpamProfile(CommonProfile): spam_field = models.CharField(max_length=20) class EggsField(CommonProfile): eggs_field = models.SmallIntegerField()
in forms.py
# forms.py
source share