Menu

Row-level permissions in Django, without a row per person
📰

Row-level permissions in Django, without a row per person

DEV Community: django·amir mohammad kashanchian·2 days ago
#DRyWNH4g
#devtodjango#devto#dev#branch#every
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.