Hi,
I have the following query which I cannot implement with the django
model API because I need to order it according to a calculated field.

query = """SELECT id FROM offers_offer AS f1
            ORDER BY (f1.original_price-f1.discounted_price) DESC
LIMIT 20"""
cursor = connection.cursor()
cursor.execute(query)
offers_list = cursor.fetchall()
offers_list_ids = [row[0] for row in offers_list]
qs = Offer.objects.filter(id__in=offers_list_ids)

The "cursor.fetchall()" method returns the ids in the right order
(according to the difference between original_price and
discounted_price) but the objects.filter method reorders the objects
according to the primary key.
How can I preserve the ordering obtained in the first place?
If that's not possible how can I reorder the queryset after the
filtering?
Is there another way of returning ordered objects for the feeds class
besides returning a queryset? (we are sending the queryset to an RSS
feed class)

Any help would be appreciated.

Thanks
Francesco


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to