I am creating an application where it will have two types of users Teacher and Student. Both of them will be able to connect to my portal, but they have different permissions. They also have different fields (the teacher has fields about name, field of studies post graduate studies etc, the student has name, name of parents, which classes he is taking etc. ). I want to extend the user model and create two types of user as I described above. I ran on this about extending the user model using the AUTH_USER_MODEL and inheriting by AbstractBaseUser thus creating in your app:
class MyUser(AbstractBaseIser):
#custom user fields
and by setting
AUTH_USER_MODEL = 'myapp.MyUser'
in the settings file.
But if I understand it correctly it can only happen for one custom user. Is it better for what I want to just go with
user = models.OneToOneField(User)
in my custome user model (e.g Teachers)? Can AUTH_USER_MODEL except a dictionary to be able to distinguish between two types of users? How much affect will have using OneToOneField in performance since the doc says that many joins will have to be performed if you use OneToOnField
Sorry I don't present any of my own code because I haven't written any code yet. I would like to have this issue cleared for me before implementing something.
Keep authentication through
MyUser
. Do something like this:on the MyUser model have a method like:
so now if you have a student user
u
you can sayyou can add more errorhandling etc yourself.