按相关对象的数量排序
我有下一个模型:
class Sentence(models.Model):
text = models.CharField(max_length=200)
language = models.ForeignKey(Language)
pub_date = models.DateTimeField()
class Traduction(models.Model):
sentence_from = models.ForeignKey(Sentence, related_name='st_traductions_from')
sentence_to = models.ForeignKey(Sentence, related_name='st_traductions_to')
我想按照与它们相关的 Traduction 对象的数量来获取句子对象的顺序。我尝试过:
sentences = Sentence.objects.annotate(num_traductions=Count('st_traductions_from')) \
.order_by('-num_traductions')
但是当我迭代它时它会引发下一个异常:
Caught DatabaseError while rendering: This query is not supported by the database
我正在使用 appengine 和 Django-nonrel。
谢谢。
I have the next models:
class Sentence(models.Model):
text = models.CharField(max_length=200)
language = models.ForeignKey(Language)
pub_date = models.DateTimeField()
class Traduction(models.Model):
sentence_from = models.ForeignKey(Sentence, related_name='st_traductions_from')
sentence_to = models.ForeignKey(Sentence, related_name='st_traductions_to')
I want to get sentence objects order by the number of Traduction object related with them. I tried it with:
sentences = Sentence.objects.annotate(num_traductions=Count('st_traductions_from')) \
.order_by('-num_traductions')
But it raise the next exception when I iterate it:
Caught DatabaseError while rendering: This query is not supported by the database
I'm using appengine and Django-nonrel.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅:App Engine 数据存储区查看器,如何使用使用 GQL 显示记录计数?
GQL 中没有计数聚合,即
count(*)
。请参阅 http://code.google.com/appengine/articles/sharding_counters.html 另一种方法。See: App Engine Datastore Viewer, how to show count of records using GQL?
There is no count aggregate in GQL, i.e.
count(*)
. See http://code.google.com/appengine/articles/sharding_counters.html for an alternative approach.