开发者

Order by number of related objects

开发者 https://www.devze.com 2023-04-12 07:43 出处:网络
I have the next models: class Sentence(models.Model): text = models.CharField(max_length=200) language = models.ForeignKey(Language)

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 rel开发者_如何学Pythonated 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消