I have a model class Department
with a field name
. I have another Model Student
with a foreign key to Department
. I want to control access to Student
objects based on department. That is, a user with permission to edit the department with name "CS" can only edit that fields. How this can be achieved in Django? (I'm using django 1.8, python3)
Edit
class Department(models.Model):
name = models.CharField(_('department name'), max_length=255)
class Students(models.Model):
first_name = models.CharField(_('first name'), max_length=30)
last_name = models.CharField(_('last name'), max_length=30)
department = models.ForeignKey('Department')
Also I'm creating required permissions dynamically while adding new department.(eg: if department.name for new entry is 'CS', 2 permissions like 'view_CS' and 'edit_CS' will be created)