开发者

Django--Model Construction (User Profile or Seperate Model)

The phrasing of the title may be a little confusing. I have an app that has users with varying permission levels (admin and non-admin).

I was unsure which of the following constructs was preferable: just go with User_Profile and add an admin field or create two models (one for admin and one for )

class User_Profile(models.Model):       
    user=models.ForeignKey(User, unique=True)
    employer=models.ForeignKey(Company,blank=True)
    admin=models.BooleanField(default=False)
    phone=models.CharField(blank=True)

Is this preferable to creating a separate table for Admins that just links to User and Employer through ForeignKeys? My views will be checking each user for Admin status, so I was concerned that querying a large User_Profile table over and over again might become expensive.

Probably not at the stage to optimize this, but I'm just curious about best p开发者_运维问答ractice.


I'd actually recommend Django's built in user permissions over either of those options: https://docs.djangoproject.com/en/dev/topics/auth/#methods

Here's a quick tutorial to help you get started: http://parand.com/say/index.php/2010/02/19/django-using-the-permission-system/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜