2007/3/28, Merric Mercer <[EMAIL PROTECTED]>:
>
> I am currently creating a query set of a Model. I'm then iterating
> through the query set to create a calculation called "total".
> At the end of each loop I am adding "total" to the query set. Example:-
>
> qs= Cash.objects.all()
> for i in qs:
># calculate total
>i.total = total
>
> Note: The Cash object has no data field called "total". I don't want
> to save this to the database because it is different for each user, so
> its created dynamically
> for each view.
>
> So far so good. This works very well and allows me to iterate over the
> query set and the dynamically created attribute "total" in the template.
>
> However, I would now like to sort the qs using "total.". Since there
> is no record in the DB I'm guessing that order_by will not work. Can
> anybody advise on a way.
You can make a custom sort_ by_total() function, create a list from
the queryset result and sort the list with sort() and sort_by_total.
I remember doing that some time ago and it worked but if the queryset
result is big you can suffer of performance problems.
Regards.
--
Marcelo Ramos
Fedora Core 6 | 2.6.19
Socio UYLUG Nro 125
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---