How to add a Manager from Field
|March 4, 2009||Posted by forumadmin under TechQns||
What i want to do is when some model use my field, it will automaticaly add custom manager to that model.
As far as i know, contibute_to_class provide such functionality
class MyCustomField(CharField): def contribute_to_class(self, cls, name): super(MyCustomField, self).contribute_to_class(cls, name) setattr(cls, 'custom_manager', CustomManager())
The problem is that in my custom manager i use self.model._default_manager to do queries on default manager but when i try to do it, django says AttributeError: ‘NoneType’ object has no attribute ‘_default_manager’
If i dont use contribute_to_class and write custom manager iside my model class, it works as expected. What can be the problem?
|Asked By – user20955||Read Answers|