Tuesday, January 31, 2012

Re: about QuerySet

do you mean that queryset will query database every time i call
user[0]?

On 1月30日, 午前9:29, akaariai <akaar...@gmail.com> wrote:
> On Jan 20, 10:12 am, newme <dllizh...@gmail.com> wrote:
>
> > user = User.objects.filter(pk="XXXX")
> > user is a QuerySet
>
> > every time i call user[0], i returns a different reference.
>
> > maybe it should be a python question.
> > i want to know i QuerySet does that.
>
> The reason is that Django does not do "instance caching". That is, you
> will get different reference each time from a queryset because that is
> how it works. If you need to use the same instance, then you need to
> store that somewere yourself. This is all the help I can give based on
> your question.
>
>  - Anssi

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment