G
G
glader2018-08-10 13:22:22
Django
glader, 2018-08-10 13:22:22

How to add multiple mixins to admin panel?

I have two admin mixins. Each adds something different to actions (like https://github.com/jrief/django-admin-sortable2/bl... ). Is it possible to make both of them work? If I just inherit from both of them, the first one mentioned will work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Astrohas, 2018-08-10
@Astrohas

The mechanism is

class A:
    def say(self):
        print('Hello')

class B:
    def say(self):
        print('HI')

class C(A, B):
    def say(self):
        A.say(self)
        B.say(self)

с = С()
c.say() # Hello \n HI

that is, in the descendant class, do something like this:
def get_actions(self):
   
   Mixin1.get_actions(self)
   Mixin2.get_actions(self)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question