If there are two models, each of which requires the other, they should usually be combined into one model.
In any case, probably the best way to structure classes. Personally, I would build the class UserProfileas follows:
class UserProfile(models.Model):
user = models.OneToOneField(User)
administrator = models.BooleanField()
or perhaps:
class UserProfile(models.Model):
user = models.OneToOneField(User)
class AdministratorProfile(UserProfile):
or even:
class UserProfile(models.Model):
user = models.OneToOneField(User):
class AdministratorProfile(models.Model):
profile = models.OneToOneField(UserProfile)
any of these methods should work.
source
share