I am trying to understand how to create custom groups in Django, so that the groups are related to the application, not Project.
For example, when a user wants to create a company, he must be the owner of the company:
model
class Company(models.Model): owner = models.ForeignKey(User) name = models.CharField(max_length=64, unique=True) description = models.TextField(max_length=512) created_on = models.DateTimeField(auto_now_add=timezone.now) class Meta: permissions = ( ("erp_view_company", "Can see the company information"), ("erp_edit_company", "Can edit the company information"), ("erp_delete_company", "Can delete the company"), )
View
# Create your views here. def register(request, template_name='erp/register.html'): if request.method == 'POST': company_form = CompanyRegistrationForm(request.POST) if company_form.is_valid():
Here are the questions:
1) Instead of Group.objects.get_or_create(name="erp_admin") I would like to have CompanyGroup.objects.get_or_create(name="admin") so that the application groups are limited by the application.
2) How can I match the permissions defined in the Meta class of each model to a group?
3) User groups are associated with the company, this means that each company has an Admin group, which begins with the owner. The owner can create the user as a "Manager". The manager can create groups / permissions, add users, set permissions for the user, but cannot in any case CRUD admin groups. Thus, there is a hierarchy in groups (I believe that the hierarchy depends on the rights added to the group).
To make this clearer, you can see a concept image: 
So, I think the main problems are:
1) How to inherit groups to create custom groups.
2) How to match model permissions for a group.
3) How groups may be limited by CompanyID.
I hope the problem is well defined. Let me know if I clarify anything.
Thanks in advance for your support.
Change 1)
For point 3, I found this answer on SO: Extend django groups and permissions , but then the problem is how to request this data and how to check permissions, And how could you override the save () method to add meta information to the "name property "? The name of the group may be something like: "company_id # admin" or "company_id # manager".