views:

99

answers:

1

Hi,

this question is about the last example on Custom managers and model inheritance.

I want to be able to do something similar to the following:

class ExtraManagerModel(models.Model):
# OtherManager class supplied by argument shall be set as manager here

    class Meta:
        abstract = True

class ChildC(AbstractBase, ExtraManagerModel(OtherManager)): # That doesn't work, something like that
    ...
    # Default manager is CustomManager, but OtherManager is
    # also available via the "extra_manager" attribute.

The whole purpose of this is that I don't want to write an ExtraManagerModel class for every overwritten manager in order to keep the default manager of the parent class (AbstractBase).

Any ideas?

A: 

I am absolutely not sure that I understand your question. Your code snippet seems to be contradicting the comment underneath it.

Your code snippet looks like you want to be able to have different ExtraManagerModel classes. If that is the case, you can use an abstract class that is implemented by those ExtraManagerModels, and you inherit the abstract parent of those classes for the childC class.

Hope this helps.

txwikinger
I see now, it is a weird question, cause it doesn't do what it wanted in the end anyway. I am better off redeclaring the supposed default manager in the model before any other managers.
stefanw
For anyone who understood my problem and is looking for a solution: I ended up using class factories: functions that declare customized classes in them and return them.
stefanw