omji / django-tabbed-admin

Easily add tabs to django admin forms
BSD 3-Clause "New" or "Revised" License
63 stars 68 forks source link

Django Tabbed Admin fail when has_change_permission is false #34

Open iwalucas opened 5 years ago

iwalucas commented 5 years ago

I have an admin class like this:

from tabbed_admin.admin import TabbedModelAdmin
class mlp(TabbedModelAdmin):
    model=Book
    tab_overview=(        
       ("",{"fields": ('name','status',),}), 
    ) 
    tabs=(
        ('Overview',tab_overview), 
        )

    def has_change_permission(self, request, obj=None):
        return False

When I try to open that in admin, I get:

"Key 'name' not found in 'BookForm'. Choices are: ."

Any idea what it may be? It works fine with the has_add/delete_permission.

Tks

JacoBezuidenhout commented 4 years ago

I am having the same problem as @iwalucas .

Do you have a possible workaround for this?

BestCaseManagement commented 4 years ago

Same here, any ideas?

ibraraslam91 commented 4 years ago

@BestCaseManagement @JacoBezuidenhout @iwalucas Not sure if this is a correct solution but for user with view only permissions I have to override get_form TabbedModelAdmin with change = False, here is my code snipe:

def get_form(self, request, obj=None, change=False, **kwargs):
        request._obj_ = obj
        return super(RoomAdmin, self).get_form(request, obj, **kwargs)

If you'r able to find a better solution please share with us.