Add group to a specific user in a model

Hello everybody. I want to add the chairman to a group with several permissions in code. I don’t have any experience with groups or adding permissions in code. please if anyone can guide me or any resources will be helpful. thanks in advanced


class ExamCommittee(models.Model):
      exam_system = models.ForeignKey(ExamSystem, to_field='year' , on_delete=models.CASCADE)
      chairman = models.ForeignKey(Staff, on_delete=models.CASCADE, related_name='chairman')
      member_1 = models.ForeignKey(Staff, on_delete=models.CASCADE, related_name='member_1')
      member_2 = models.ForeignKey(Staff, on_delete=models.CASCADE, related_name='member_2')
      exam_year = models.CharField(max_length=10)




The Django Group model is just another model - there’s nothing “different” about it. You work with it in exactly the same ways that you work with any other model in Django. (That includes creating, updating, or deleting them; or assigning users to them.)

Permission is another model. You work with it in the same way as with any other model.

What makes these models “special” is that there are the set of functions and mixins that use these models to allow you to manage access to your site.

See the docs at:

Off-topic side note: That’s not how I would model an ExamCommittee. I would create ExamCommittee as the through model of a many-to-many relationship between Staff and ExamSystem, where exam_year and role would be extra fields on that model. It may seem like more work up front, but it would tend to make things easier in the long run going forward - depending upon your needs to manage these committees.