Your site may have 2 types of user - but that doesn't mean you have 2 user models. The user model is primarily for determining authentication; authorisation can be handled separately.
So - set up a user model the way you normally would; then define a Teacher model and and Student model, each with a OneToOneKey to User. The user logs in, and you can determine what type of user they are by looking for the existence of a "teacher" or "student" attribute. You can then perform permission checks etc as appropriate by looking for user.student.<some property> or user.teacher.<some property>.
As a side effect, this also allows for the edge case where a student is *also* a teacher - e.g., at a university, I might be studying business while teaching computer science.
Yours,
Russ Magee %-)
On 24 Jul 2017, at 7:09 PM, stan <seranotannason@gmail.com> wrote:What is the best way to create multiple user types in Django 1.11?For example, an e-learning platform will need 2 user models: Students and Teachers, which have different permissions and different attributes/methods--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a5127741-73a1-4a34-8e4e-ab753c6aab7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment