1

I'm trying to reset my user permissions to assign new objects permissions to my user. how to achieve that ?

For Example:

having 3 chained models School & Grade & StudentRecord

Models.py:

class School(models.Model):
    name = models.CharField(_("Name"),max_length=50)
    # other fields ...
    def __str__(self):
        return self.name

class Grade(models.Model):
    code_name = models.CharField(_("Name"),max_length=50)
    school = models.ForeignKey(School,on_delete=models.CASCADE,blank=False,related_name='grades')
    # other fields ...
    def __str__(self):
        return self.code_name

class StudentRecord(models.Model):
    code_name = models.CharField(_("Name"),max_length=50)
    school = models.ForeignKey(School,on_delete=models.CASCADE,blank=False,related_name='grades')
    grade = models.ForeignKey(Grade,on_delete=models.CASCADE,blank=False,related_name="student_records")
    # other fields ...
    def __str__(self):
        return self.code_name

When I give a User as a Manager the perms (add,change,view,delete) for all objects of models which belong to specific school that User manage. If I need to change the Manager (User). I need to reset all permissions and reassign for all related objects of this specific school.

How To Acheive This Approach? any support will be appreciated.

Poula Adel
  • 609
  • 1
  • 10
  • 33
  • cannot we achieve this by determining user type? – lord stock Aug 29 '21 at 10:33
  • yup we can for sure, but for clean code sake I prefer to use `user type` or `user role` for viewing pages and url checks. and user permissions for object handling or data access – Poula Adel Aug 29 '21 at 10:41
  • 1
    Yeah I do on same as your approach I use enum class to determine user type and have rest of validation Based on user type given the model instance – lord stock Aug 29 '21 at 10:59

0 Answers0