简体   繁体   中英

Extend User Model Django 2.0

I'm starting a whole new project using Django 2.0 and python, so I'm at the beginning of deciding how to implement the Multiple User Types.

What I've read so far is that I can extend the User built-in model for django so that I would get use of django's authentication process, and create another models that links one-to-one with that user model. But actually I can't understand a little bit.

My application has three user types: Participant, Admin, Judge, each of them will view certain pages(templates) and as well as permissions.

Can someone provide me with the best practice/approach to start working on those user types.

Note: In the future, each user may have different fields than the other, for ex. Judge may have Join date while participant won't...etc

If you haven't already, the documentation seems to mention what you are trying to do.

Here is an example which creates custom user models. But I think you are essentially right. You can create an abstract base user with the standard information (name, email, etc). Then you can create a separate class which is just a model class, then set a foreign key to your abstract base user, and add additional data for that user.

class User(AbstractBaseUser):
    email = models.EmailField(max_length=255, unique=True)
    # etc

class Judge(models.Model):
    user = models.ForeignKey(User)
    # User specific data

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM