0

I need to have 2 user roles in my project: client and employer

Question number one: There is an option called 'groups' in Django admin panel.Is it the same stuff like user roles?

enter image description here

Question number 2:

Let's say that I need to add custom field like company_name to users with role customer I have read some question like this Extending the User model with custom fields in Django And I got from that I should use a property called OneToOneField(User) But still I still confused. So how can I add this custon field company_name in model?

Community
  • 1
  • 1
user2950593
  • 9,233
  • 15
  • 67
  • 131

1 Answers1

0

Answer to Q1: Groups are are for controlling the Admin interface access, with different permissions. If you try creating a group you will see that you can select permissions as well for that particular group. So I would say it is not what you want. But if you create groups without permissions you can use for your purpose as well.

Answer to Q2: Please refer to documentation for more details and examples. Here is just a basic example. For your case you need to create new model which has one to one relation to you auth user model and extends more fields as you want, for example:

USER_TYPE = {0: 'Client', 1: 'Employer'}

class MySpecialUser(models.Model):
  user = models.OneToOneField(
    settings.AUTH_USER_MODEL,
    on_delete=models.CASCADE,
  )
  type = models.IntegerField(choices=USER_TYPE.items())
  # used only for Client type
  customer_name - models.CharField(..., null=True)
Gagik Sukiasyan
  • 846
  • 6
  • 17