Python: how to inherit from two classes?
First of all I'm a python newbie.
I'm playing with Django and I'm trying to extend some classes.
Now I'm in this situation:
I have a new class
customBaseModelAdmin(admin.options.BaseModelAdmin):
#override a method of BaseModelAdmin
and I want to write another class
customModelAdmin(custom开发者_Python百科BaseModelAdmin):
that obviously inherits customBaseModelAdmin, but that has the same methods of the standard ModelAdmin.
But, since the standard ModelAdmin inherits the standard BaseModelAdmin, how can I do?
I tried with the definition
class customModelAdmin(customBaseModelAdmin, admin.options.ModelAdmin):
but it doesn't work.
Do you have any suggestion?
Thanks,
Giovanni
Just let customBaseModelAdmin inherit from ModelAdmin. You can still override the method from BaseModelAdmin.
But of course it could be that ModelAdmin also overrides this method. I would take a look at the source code of these classes to really know what is going on there.
Why not just subclass ModelAdmin for customBaseModelAdmin?
You do it like this:
class customModelAdmin(customBaseModelAdmin):
etc
加载中,请稍侯......
精彩评论