But a query isn't run until I actually do something with the object, by
loading it into memory by accessing or iterating over a queryset I'm
performing potential time consuming operations. Isn't it better to do
whatever work I can on the database? In some cases I could be doing
something similar for thousands of records, surely this wouldn't be
effective? Or am I simply overestimating the effort required for Python to
work with the results?


On Thu, May 15, 2014 at 4:14 AM, Daniel Roseman <[email protected]>wrote:

> On Wednesday, 14 May 2014 01:20:39 UTC+1, Anthony Hawkes wrote:
>>
>> Thanks for the answer! Do you think it would be practical to let the orm
>> generate the base query and then doing a replace on the column name? I was
>> thinking of this approach as a custom manager method to return a raw result.
>>
>> This would allow me the generate a case statement for the column and I
>> could dynamically create it.
>>
>> Ant
>>
> You're thinking of this in the wrong way. Do you really need this data to
> be generated by the database in the query? Once the original values are out
> of the db and made into Python objects, you've got a whole powerful
> object-orientated language available to you to do whatever transformations
> you need on the data, ie Python. And you needn't do it at a queryset level:
> each of the elements of the queryset is a model instance, and in the
> process of accessing any of the values of those instances you're
> necessarily interacting with the model object, so you can simply add
> instance methods and call those instead of the original attributes.
> --
> DR.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/ZuSxc3YXA3c/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/fb2374d5-c928-4322-a0f0-517c24586eb6%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fb2374d5-c928-4322-a0f0-517c24586eb6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Anthony Hawkes
E-Mail: [email protected]
Ph: 0400 372 260

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABqJoT0hL3U_Rt39x_wAMA%3Dtd68o8UrwkA2qJhZxT4%2BfNDDZPQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to