2

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

9
  • 2
    Django already has user "groups", which seems probably the best way, since you could have users that are admin and judge at the same time. Every group has permits that describe what users of that group can do. Commented Feb 13, 2018 at 8:57
  • No I won't have user that's judge and admin at the same time, I meant by multiple user types, is that i'm having different user types in my application Commented Feb 13, 2018 at 8:59
  • @OmarEl-elamy how about flags field? Look at django-bitfield Commented Feb 13, 2018 at 9:01
  • can you elaborate more @greesha0 ? Commented Feb 13, 2018 at 9:02
  • Permission are also mostly based on groups instead of users Commented Feb 13, 2018 at 9:10

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.