我有两种模式:
class ModManager(models.Manager):
def myfilter(self, options = dict()):
if options.has_key('not_image'):
kwargs['image__isnull'] = False
return self.filter(**kwargs)
class Model_1(models.Model):
...
objects = MyManager()
class Model_2(models.Model):
something = models.ForeignKey(Model_1)
something_else = ...
...
如何在MyManager中获取Model_2中与Model_1相关的所有数据?我想得到一个查询。我到目前为止:
in Model_1:
def get_model_2(self):
self.model_2_objs = self.model_2_set.all()
但是当我调用get_model_2函数时,它会生成许多查询。