Why can't I utilize other model objects in my custom Manager?
I want to implement a custom django.db.models.manager.Manager (let's call it MyMana开发者_Python百科ger) for MyModel.
The methods in MyManager needs to invoke filter methods on AnotherModel.
Is this possible ? I'm getting an ImportError because of this.
In your MyModel, you need to add your MyManager as an explicit manager.
class MyModel(models.Model):
objects = MyManager()
You can retain the standard Manager and have your manager both, by including this manager by another name.
class MyModel(models.Model):
myobjects = MyManager()
If you are using the django-admin, there are nuances involved in what manager's objects are picked up. You can find those and many other details from the awesome django documentation.
加载中,请稍侯......
精彩评论