Django models and permission restrictions

Models:

Company

Product

We have a parent company (the owner of all), which can create any Companyand any Product, like a sub-company or a sub-product.

Now, what I would like to do is limit which company can CRUD other companies and products.

Here are the scenarios:

Company and sub-companies (subcontractors):

Master (creates) -> Company "A"
Master (creates) -> Company "B" (creates) -> Company "C"
Master (creates) -> Company "D" (creates) -> Company "F" (creates) -> Company "G"

Purpose of the company and product:

Master (Add Product) -> Show all products
Master (assign products to top levels) -> Company "A", Company "B" and Company "D"

Product purpose for the company (management):

Company "B" (assign products only to sub-level) -> Company "C"
Company "D" (assign products only to sub-level) -> Company "F"
Company "F" (assign products only to sub-level) -> Company "G"

However, if you Company Dremove a product from a sub-level, it will also be recursively removed from all products of the sub-level.

- Django , , , ? Django Model Meta options Options.permissions... , .

+4
4
class Company(models.Model)
    parent = models.ForeignKey('self', blank=True, null=True, related_name='children')


Company.objects.get(pk=1).children.all()

, Views

0

, , - DJANGO GUARDIAN. Role Based Access Control Logic.

, django-guardian . . . :

+5

, , . () . django-mptt .

0

, / .

- , Django Organization . - - () . , Django, .

, , ( ), . , , .

, , django-mptt django-treebeard , , .

I would emphasize that this sounds like a part, because it is not entirely clear if this is exactly what you are trying to solve, and if this is all you need to solve.

0
source

Source: https://habr.com/ru/post/1671432/


All Articles