--I'm making a small test project with below user types: School Admin, Teacher, Student, Parent. And each user type will have different Permissions like School Admin has full access... Parents can only view their Childern's Activity. Teacher can see all students but can add / edit marks for their respective students only. Teachers can setup Exam etc.. Students can take exam and submit the exam, but cannot edit / add any other information. Just can edit his profile detail.
Approach 1: Do i need to create a Custom User calss and apply to each user type (ie one Custome Class.. and 4 user type calss).. and similarly have 4 different view and html pages?
Approach 2: Just have one custome class and have an field with UserType which will have the have as "SchoolAdmin", "Teacher", "Student","Parent".. and one view and html (as the data page would remain same and only data record will restrict), and somehow identify the User Type in View, and filter the record?
Definately some view or html pages will be specific to one user type only which is i am able to handle, the issue is to use same view / html page to handle all user type.
Please suggest... and any code snippet will will more helpful.
Below is the thing from approach 1, i was trying.
# models.py --------------------- class CustomUser(AbstractUser): USER_TYPE_CHOICES = ( ('SchoolAdmin'), ('Teacher'), ('Student'), ('Parents'), ) user_type = models.CharField(blank=False, choices=USER_TYPE_CHOICES) name = models.CharField(blank=False, max_length=255) country = models.CharField(blank=False, max_length=255) city = models.CharField(blank=False, max_length=255) phone = models.CharField(blank=True, max_length=255) created_at = models.DateField(auto_now_add=True) def __str__(self): return self.name class SchoolAdmin(models.Model): user = models.OneToOneField( CustomUser, on_delete=models.CASCADE, primary_key=True) class Teacher(models.Model): user = models.OneToOneField( CustomUser, on_delete=models.CASCADE, primary_key=True) photo = models.ImageField(upload_to='photos/%Y/%m/%d/', blank=True) class Student(models.Model): user = models.OneToOneField( CustomUser, on_delete=models.CASCADE, primary_key=True) teacher = models.ForeignKey(Teacher) photo = models.ImageField(upload_to='photos/%Y/%m/%d/', blank=True) class Parent(models.Model): user = models.OneToOneField( CustomUser, on_delete=models.CASCADE, primary_key=True) student= models.ForeignKey(Student)
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dbc99b6e-3d46-41c4-a5a9-1e85bbf7d8a4%40googlegroups.com.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKYSAw3ucCKdYsctEMBtMBY9G0Na%2BzQiHKRzJ9w-%3D7RZ6ZGh3A%40mail.gmail.com.
No comments:
Post a Comment