dealing with 3 different user + admin user in django? -
i getting django , using drf build restful api have 4 different users admin , has access admin panel brokers can on site cannot access admin panel buyers can 2 action buy , search man in middle can except 1 thing way doing right have baseclass shared fields between users
class siteuser(models.model): name = models.charfield( max_length=255, null=false, blank=false, db_index=true) email = models.emailfield(max_length=254, unique=true) address = models.charfield(max_length=255, null=false, blank=false) city = models.charfield(max_length=254, null=false, blank=false) active = models.booleanfield(default=1) = models.textfield() class meta: abstract = true
and have 3 other models different fields , onetoone relation user model
class manger(siteuser): manger = models.onetoonefield(settings.auth_user_model) manager_licsences_number = models.integerfield() class buyer(siteuser): buyer = models.onetoonefield(settings.auth_user_model) class seller(siteuser): seller = models.onetoonefield(settings.auth_user_model) trust_number = models.integerfield()
but feel method wrong had ideas in head
1- i've been looking creating own abstract base class user model , using model user model , using admin panel admin user .
2- abstracting user model 3 times , making 3 user objects , building custom oath 3 different users think not approach
so guys think best way handle ?
if user classes have special field, maybe approach not bad.but can try approach using sort of field, can store data related special fields. example:
class siteuser(models.model): broker = models.onetoonefield(settings.auth_user_model) name = models.charfield(max_length = 255, null = false, blank = false, db_index = true) email = models.emailfield(max_length = 254, unique = true) address = models.charfield(max_length = 255, null = false, blank = false) city = models.charfield(max_length = 254, null = false, blank = false) active = models.booleanfield(default = 1) = models.textfield() extra_field = models.charfield(max_length=255, null=true) #for special data class manager(siteuser): class meta: proxy = true @property def manager_licsences_number(self): return self.extra_field @manager_licsences_number.setter def manager_licsences_number(self, value): self.extra_field = value ...
thus, need not create multiple tables manager
, buyer
, seller
. , saving mechanisom simple: myapp.models import manager
m = manager() m.manager_licsences_number = '1-22-33-4' .. m.save() print(m.manager_licsences_number)
Comments
Post a Comment