假设我的某个应用程序中有一个奇怪的Manager定义的Django模型:
# this code cannot be altered:
class WeirdManager(models.Manager):
def get_query_set(self):
return super(WeirdManager, self).get_query_set().none()
class HasWeirdManager(models.Model):
value = models.IntegerField()
objects = WeirdManager()
all_objects = models.Manager() # may or may not exist
all_objects
可能存在也可能不存在;无论如何我一般都不知道它存在。如何获得此类型的“未受破坏的”models.Manager
的引用?
# this is my own code:
this_is_the_question(HasWeirdManager).get(pk=1)
# another example:
this_is_the_question(HasWeirdManager).update({'value': 10})
即,在上文中,this_is_the_question
的价值是什么?
答案 0 :(得分:3)
那很快:
答案是HasWeirdManager._base_manager