【发布时间】:2011-04-26 03:43:26
【问题描述】:
我想将下面的 foo/view 代码放入 Foo 模型对象下的属性中,但调试消息显示“找不到 bar”。为什么它在views.py中可以工作,但是当我将它放在models.py中时不起作用(我确实记得导入Bar)?
谢谢!
foo/models.py
类 Foo(models.Model):
title = models.CharField(_(u'Title'), max_length=600)
bar/models.py
类栏(models.Model):
foo = models.ManyToManyField(Foo)
eg_id = models.PositiveIntegerField(_(u'Example ID'), default=0)
foo/views.py
from django.db.models import Count
qs = Foo.objects.filter(
bar__eg_id__in=id_list
).annotate(
bar_count=Count('bar')
).order_by('bar_count')
【问题讨论】:
-
能否请您格式化源代码?有点难读
标签: django django-models