Django's permission system answers one question well: may this person change
orders? Real projects ask three more, and Django leaves each of them to you.
Which orders? A branch manager edits their branch's orders, not every branch's. A customer reads their own.
Which fields? A manager reads an order, but not what the shop paid.
Which values? Anybody who may edit an order may fix its item - but only whoever may approve sets it to approved .
The usual answer is a filter in the view:
def get_queryset ( self ) : return Order . objects . filter ( branch = self . request . user . branch )
Enter fullscreen mode
Exit fullscreen mode
It works, until it has to be written again - in the list view, the detail view,
the API, the admin class, the CSV export, the report. The one that is forgotten
does not fail.…