Reputation: 221
In my Django 1.6.5 project, my user registration form creates a UserProfile
that has a one-to-one relationship with the created User
. My views assume that when a user is logged in, s/he has an associated UserProfile
in the database.
However, superusers are created through the manage.py
file, and don't have an associated UserProfile
, which causes the views to throw an error. This isn't a huge issue, since I will be the only one with a superuser login, but it still seems like a bad idea to leave the website like that.
There's nothing the app can really do if there is no UserProfile
, so should I code in a special case where the views throw an explicit error warning the user that s/he is logged in as a superuser and cannot use the website? I could also make a UserProfile
manually for the superuser, but that seems silly.
Or is there a way to enforce the existence of a UserProfile
for each User
at the database level? If so, how would I create a superuser simultaneously with a UserProfile
, since it's being created from the command line?
Upvotes: 2
Views: 56
Reputation: 52313
Keep them separate:
Although it's probably more conventional to Inherit/Extend/Encapsulate your User with/from the default django User. Here we go... docs for extending the user model
Upvotes: 1