0

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.

Ivan
  • 1,477
  • 3
  • 18
  • 36

1 Answers1

1

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.

Community
  • 1
  • 1
Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • Ok. Finally I did it adding a "num_traductions" field in Sentence model which is incremented when a new Traduction is added and related with it. I think this is a more efficient way to resolve it. – Ivan Oct 14 '11 at 09:19