bruth / django-preserialize

Convert your model instances and querysets into dicts and list with style.
http://bruth.github.io/django-preserialize
BSD 2-Clause "Simplified" License
41 stars 6 forks source link

Evaluating querysets #10

Closed stargazer closed 10 years ago

stargazer commented 10 years ago

Hi,

Firstly, thanks for this wonderful piece of software :) I have a short question. Method queryset_to_list from the serialize.py module,

def queryset_to_list(queryset, **options):
    ...
    return [model_to_dict(x, **options) for x in queryset.iterator()]

evaluates the queryset using an iterator. Doing so, has the downside that a queryset that has been evaluated already (on application level, for example), will be re-evaluated here. My main problem with this, is that any ad-hoc data attached to the model instances that were previously loaded when the queryset was first evaluated, are lost.

Contrary to that, if the queryset is evaluated normally without an iterator,

def queryset_to_list(queryset, **options):
    ...
    return [model_to_dict(x, **options) for x in queryset]

it won't be re-evaluated again, if it has already been evaluated on application level, and therefore the implication I mentioned above is eliminated.

I'm curious on your thoughts,

bruth commented 10 years ago

Good catch! I will change this behavior.

bruth commented 10 years ago

1.0.7 Released Thanks again

stargazer commented 10 years ago

Greatly appreciated sir!