我有两种模式:
class Model1(models.Model):
field1 = models.BooleanField()
field2 = ...
class Model2(models.Model):
field21 = ...
field22 = models.ForeignKey(Model1)
objects = FilterManager()
以及如何在FilterManager(Model1)中排除对象包含Model1.field1 = False?
我的FilterManager:
class FilterManager(models.Manager):
def optfilter(self, options = dict()):
if options.has_key('option'):
kwargs['field21'] = options['option']
return self.filter(**kwargs)
答案 0 :(得分:2)
尝试这样的事情:
Model2.objects.exclude(field22__field1=False)