title: django access control based on a model field value
body: <p>I have a model class <code>Department</code> with a field <code>name</code>. I have another Model <code>Student</code> with a foreign key to <code>Department</code>. I want to control access to <code>Student</code> 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)</p>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>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')
  </code></pre>
  
  <p>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)</p>