Use has_add_permission
, has_change_permission
and has_delete_permission
with a custom ModelAdmin
(in admin.py
):
class ArticleAdmin(admin.ModelAdmin):
def has_add_permission(self, request):
# Nothing really to do here, but shown just to be thorough
return super(ArticleAdmin, self).has_add_permission(request)
def has_change_permission(self, request, obj=None):
if obj is not None:
return obj.location == request.user.get_profile().location
else:
return super(ArticleAdmin, self).has_change_permission(request, obj=obj)
def has_delete_permission(self, request, obj=None):
if obj is not None:
return obj.location == request.user.get_profile().location
else:
return super(ArticleAdmin, self).has_delete_permission(request, obj=obj)
admin.site.register(Article, ArticleAdmin)