django_reverse_admin icon indicating copy to clipboard operation
django_reverse_admin copied to clipboard

Conflict with BaseUserAdmin

Open anufry opened this issue 4 years ago • 1 comments

Hello!

Tried to use with Django 2.2 from django.contrib.auth.admin import UserAdmin as BaseUserAdmin class DealersAdmin( ReverseModelAdmin, BaseUserAdmin,): fieldsets = ((None, {'fields': ('email','password','first_name','last_name',)}),) add_fieldsets = ((None, {'fields': ('email','password1', 'password2','first_name','last_name',)}),) inline_type = 'stacked' inline_reverse = ['legal'] and got

"Key 'password1' not found in 'DealerForm'. Choices are: company, email, first_name, last_name, markup, password, phone."

So I can add user with 'password1/password2 fields, but got the error when trying to change this user

Is there any conflict with BaseUserAdmin or is this my misunderstanding?

anufry avatar Jan 29 '21 17:01 anufry

for anyone else looking into fixing this temporarily,

adding this to your ModelAdmin will do the trick:

    def get_inline_instances(self, request, obj=None):
        own = list(filter(
            lambda inline: inline.has_view_or_change_permission(request, obj) or
            inline.has_add_permission(request, obj) or
            inline.has_delete_permission(request, obj), self.tmp_inline_instances))
        instance = super(ReverseModelAdmin, self).get_inline_instances(request, obj) # <- change this

        if obj == None: # <-- add
            return own  # <-- thiss
        
        return own + instance # <-- and this

abdul-hamid-achik avatar Jul 06 '22 20:07 abdul-hamid-achik