4
If two models exist such that each requires the other, they should usually be combined into a single model.
In any case there is probably a better way to structure the classes. Personally I would construct a UserProfile
class as follows:
class UserProfile(models.Model):
user = models.OneToOneField(User)
administrator = models.BooleanField()
or possibly:
class UserProfile(models.Model):
user = models.OneToOneField(User)
class AdministratorProfile(UserProfile):
# attributes
or even:
class UserProfile(models.Model):
user = models.OneToOneField(User):
class AdministratorProfile(models.Model):
profile = models.OneToOneField(UserProfile)
any of these methods should work.
0
Iโm not totally sure I fully understand the differences between Administrator
, Account
, and contrib.auth.User
,
This feels like the is-a vs has-a discussion. It sounds like Administrator
is a User (really, a UserProfile, for reasons peculiar to django), and Administrator has an Account
. Accounts do not have anything, since they cannot both own and be owned.
This is like a bank account vs a bank customer. Bank customers own their accounts, not the other way around. On the other hand, bank accounts have a list, and that list is the bank customers that may use the account.
- [Django]-Django, PostgreSQL, set_autocommit and test cases
- [Django]-./manage.py test results in django.db.utils.OperationalError: no such column: MyNewColumn
- [Django]-Using Django ORM inside Tornado, "syncdb" doesn't work
- [Django]-Django Foreign Keys Breaking with Multi-Table Inheritance
- [Django]-Django Markdown Editor does not show up