0

I am upgrading a Django project from Django 1.11. I have successfully upgraded the project upto Django 2.1. When I upgraded to Django 2.2, I got this error message "(admin.E130) name attributes of actions defined in class AdimClass(not real name) must be unique"

The admins classes are

class AAdmin(admin.ModelAdmin)

    def custom_action(self, request, queryset):
        # perform  custom action
        .....

    def custom_action_2(self, request, queryset):
        # another custom actions
        .....


    action = [custom_action, custom_action_2]


class BAdmin(AAdmin):

    def custom_action(self, request, queryset):
        # performs different actions but has the same name as AAdmin action
        .....
    actions = AAdmin.actions + [custom_action]

problem: (admin.E130) name attributes of actions defined in class AdimClass(not real name) must be unique

If I remove the custom_action from AAdmin, the error is resolved but the action is no more available for other classes which inherits AAdmin.

Goal: keep the action in parent class AAdmin and override it on child class BAdmin.

Note: The code is working fine upto Django 2.1.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Faizan
  • 268
  • 2
  • 9

1 Answers1

1

The issue is that you are trying to add the same action name "custom_action" to BAdmin twice, the first is inherited by AAdmin. The solution is to not include the duplicate action. A possible solution:

class BAdmin(AAdmin):

    def get_actions(self, request):
        actions = AAdmin.actions
      
        if 'custom_action' in actions:
            del actions['custom_action']
    
        return actions + [custom_action]
Aiky30
  • 785
  • 6
  • 13