Hi, I've also posted this question on StackoverFlow and haven't got any response surprisingly. Here is the link <https://stackoverflow.com/questions/60048405/django-extending-models-with-multi-role-users-and-multiple-requirement-types> .
I am new to Django only 1 week and I am stuck with scenario I need help with. This is kind of core concept and I apologize in advance for my lack of knowledge. I've extended the base user model like below with multiple roles. Now each role has distinct requirements for their profiles. I need help to understand that how to extend Students or Staff further. There are two scenario I need to extend them. 1. Both can have similar extended models like addresses below. 2. Both can have different extended models like Students have CurrentCourse and Staff does not. Staff has Salary model and Students does not. class User(AbstractUser): is_student = models.BooleanField(default=True) is_staff = models.BooleanField(default=True) class Student(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, null=True) dob = models.CharField(max_length=30, blank=True) location = models.CharField(max_length=30, blank=True) class CurrentCourse(models.Model): student = models.OneToOneField(Student, on_delete=model.CASCADE)# Can I extend it like this or do i need some other approach? .... class Staff(models.Model): ROLES = (('Teacher', 'Teacher'), ('Professor', 'Professor'), ('Administration', 'Administration')) user = models.OneToOneField(User, on_delete=models.CASCADE, null=True) role = models.CharField(max_length=100, choices=ROLES) website = models.CharField(max_length=100, blank=True) # Both types of Users can have multiple addresses and both Students and Staff needs addressess, not sure how to extend this with ForeignKey. class Address(models.Model): street = models.CharField(max_length=200) city = models.CharField(max_length=50) country = models.CharField(max_length=50) class Salary(models.Model): staff = models.OneToOneField(Staff, on_delete=models.CASCADE) current_salary = models.DecimalField(max_digits=10, decimal_places=2) Finally please let me know how can I apply validators on each model for instance I did sub-classed 'User' to all models instead of Student or Staff. How to apply a validator on OneToOneField like below: class Salary(models.Model): staff = models.OneToOneField(User, on_delete=models.CASCADE, validators=[some-validator]) Thank you in advance for your kind help for this. Best Regards, Zaheer -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/51552bea-877b-4c66-8a7a-42a68ca761e5%40googlegroups.com.