A G
A G

Reputation: 1117

django model permission vs group permissions

My django model looks like this:

class testModel(models.Model):
    ...
    def has_add_permission(self, request):
        return False
    ...

My group permission looks like this:

employee: testApp | testModel | can add testModel

The user can still add objects:

enter image description here

It look like the the has_add_permission function is being ignored as the button only disappears when the permission is removed from the group;

group permission: can add testModel and has_add_permission returns true

group permission: can add testModel and has_add_permission returns false

group permission: cannot add testModel and has_add_permission returns true

group permission: cannot add testModel and has_add_permission returns false

Is this expected behaviour?

Upvotes: 1

Views: 283

Answers (1)

Ralf
Ralf

Reputation: 16515

If you are referring to this part of the docs, you should know that there they are talking about the ModelAdmin methods, not the model directly.

class MyModelAdmin(admin.ModelAdmin):
    ...

    def has_add_permission(self, request):
        return False

I don't think it is supposed to work by defining those methods directly on the models, you will have to define them in the admin class of that model.

Upvotes: 1

Related Questions