"Its not a bug, its a feature."
See:
https://docs.djangoproject.com/en/1.9/ref/models/querysets/#when-querysets-are-evaluated
If you were designing Django's internals, you might have decided that the
Queryset "should behave" in a certain way, but the designers have chosen
this approach. There is no "disguise" about this; it's well-known and
well-documented.
On Friday, 11 December 2015 15:43:45 UTC+2, Ws Hu wrote:
>
> import json
> from myapp.models import MyModel
>
>
> x = json.dumps(MyModel.objects.values_list('myField', flat=True)) # "[]
> is not JSON serializable"
> x = json.dumps([x for x in MyModel.objects.values_list('myField', flat=
> True)]) #ok
>
>
>
> ####
> It seems that the database is accessed only if the result of
> objects.filter()/all()/values_list()/... is printed/iterated/... .
> It's fine, but I think the methods of model manager like
> filter()/all()/values_list() should behave as if it is processing python
> objects. I have not yet digged into json module, but it did penetrated
> django's disguise.
>
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/122c7ed6-a79d-4c84-b5fa-28899040f64d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.