views:

118

answers:

1

I'm developing an SAAS and having the hardest time wrapping my brain around why I need to use "User" for anything other than myself. I don't know why but it makes me queezy to think that I, as the developer/admin of the entire software, with full Django Admin access (like the Eye of Sauron), have the same type of User object as an "Account" holder's "UserProfile" has. Please help me understand why this is necessary.

Example:

class Account(models.Model): # represents copporate customer
    admin = models.ForeignKey(User)
    # other fields ...

class UserProfile(models.Model):
    user = models.ForeignKey(User)
    account = models.ForeignKey(Account)

It feels like I'm mingling the builtin Admin functionality with my account holders' users' functionality. Is this just for purposes of reusing elements like request.user, etc.?

+1  A: 

Well, reuse of code and functionality might be a happy side-effect, but fundamentally I don't think this is broken.

A User represents someone using your website. At the base level it doesn't matter who that person is or what features or functionality they need - just that they make requests and can be identified in some way.

Further functionality can be added in different layers, either through built in components like Groups or Permissions, or through something else you build on top yourself as you are doing in your example.

Andy Hume
@Andy Hume What about all the attributes: username, first_name, last_name, email, password, is_staff, is_active, is_superuser, and so on. Do I need to use all of these when I create a User? I guess I'm just having trouble understanding how all these attributes could fit into my own system. Is it that I should use all these attributes? If is_superuser=True doesn't that give them an all access pass if they just type www.example.com/admin/? I looked at Django-Annoying and it has a AutoOneToOneField() that creates the User for you, but what about setting all the attributes?
orokusaki
You certainly don't have to use all the attributes. You can expose as few or as many as makes sense depending on what you want a specific type of User to be able to do.Yes, is_superuser=True should be reserved for only yourself and the very privileged few that need it. A 'normal' user would have it set to False.You can set all the attributes though the OneToOneField if you need them, eg. profile.user.last_name = "Jones"
Andy Hume