0
数我的下一个型号:整理相关对象
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。
谢谢。
好的。最后,我在句子模型中添加了一个“num_traductions”字段,当添加一个新的Traduction并与之相关时,该字段会增加。我认为这是解决问题的一种更有效的方法。 – Ivan