I've been searching Google and Stackoverflow for the last 3 days now and couldn't find anything similar. I'd like to extend or use the django groups and permissions.
Let's say we got some Projects with different Teams and Users.
class Project(models.Model):
owner = models.ForeignKey(User)
name = models.CharField(max_length=100)
class Team(models.Model):
project = models.ForeignKey(Project)
members = models.ManyToManyField(User)
name = models.CharField(max_length=100)
permission = models.ManyToManyField(Permission)
Now - everything's fine. Now what I want is to extend the existing Auth.Group delivered by django so I could use request.user.has_perm...
the direct way.
So, let's change the Team-Model into
class Team(Group):
project = models.ForeignKey(Project)
members = models.ManyToManyField(User)
This extends the existing Group. The name
and permissions
field comes direct from the Group-Model. If I create a new Team, there will be a Group added, too. That's great.
With a custom save
method I could also add, that the user
listed in members
, will be added to the created Group and gets the permissions granted to the Team/Group.
Now my problem is, the name
field of the Group is unique - so I couldn't add an Admins-Team for each Project.
I thought about adding another name-field for the frontend and generate a unique string for the name field of the Group-Model. But hmmm....is there a better solution for multiple custom Groups? Maybe one got an idea? Thank you in advance!