tags:

views:

149

answers:

3

Hi everybody!

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(customBaseModelAdmin):

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

+2  A: 

Why not just subclass ModelAdmin for customBaseModelAdmin?

pib
because I want to keep the original version of ModelAdmin (that is the one provided by Django).
Giovanni Di Milia
@Giovanni Di Milia: Subclassing does not mean that the original class is destroyed ;)
Felix Kling
Yes, but how can I subclass ModelAdmin for customBaseModelAdmin? I mean... can you make an example?
Giovanni Di Milia
@Giovanni Di Milia: It is the same what I said in other words.
Felix Kling
+2  A: 

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.

Felix Kling
I already gave a look to the source code... I think your suggestion is right, but I have to find how to override in the right way....Thanks.
Giovanni Di Milia
Done! Thank you very much!
Giovanni Di Milia
A: 

You do it like this:

class customModelAdmin(customBaseModelAdmin):
    etc
Lennart Regebro