You may go with Russ' solution or you may create two UserGroups, one for Students and one for Teachers, each having different access rights. This also allows for the edge case where a person may be a teacher and a student on the same time.
Different behavior at python level can be implemented by using to proxy models, one for Student and one for Teacher, but this solution works if you don't want to have different attributes on them.
More on proxy here.
marți, 25 iulie 2017, 04:02:09 UTC+3, Russell Keith-Magee a scris:
-- Different behavior at python level can be implemented by using to proxy models, one for Student and one for Teacher, but this solution works if you don't want to have different attributes on them.
More on proxy here.
marți, 25 iulie 2017, 04:02:09 UTC+3, Russell Keith-Magee a scris:
Short version: You don't.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 <seranot...@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...@googlegroups.com .
To post to this group, send email to django...@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 .
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/034f4c37-788c-4a81-8f6c-a0143397029e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment