Answer the question
In order to leave comments, you need to log in
How to properly model the users table?
There are 2 categories of users,
"Master" and "Customer"
if the user has the type "Master", then
he must have his own special field, for example "Electrician",
and if the type is "Customer", then it is logical that he has this field should not.
Currently implemented like this:
USER_CATEGORY = ((1,"Customer"), (2,"Master"))
class UserCategory(models.Model):
choice=models.IntegerField(choices=USER_CATEGORY, db_index=True)
def __str__(self):
return str(self.choice)
class MasterCategory(models.Model):
category_name=models.CharField(max_length=200, db_index=True, )
description=models.TextField()
def __str__(self):
return self.category_name
class User(models.Model):
name=models.CharField(max_length=200)
user_category=models.ForeignKey(UserCategory)
master_category=models.ForeignKey(MasterCategory, null=True, blank=True)
def __str__(self):
return self.name
Answer the question
In order to leave comments, you need to log in
Make one general ABSTRACT model in which there will be all COMMON fields for the Master and the Customer. Then inherit from it the MasterUser and CustomerUser tables, which will already have their own fields, those that are needed for a particular type of user.
For an abstract model, do not forget to specify:
class Meta:
abstract = True
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question