Re: Best Queryset Practice

2015-06-23 Thread Paritosh Gupta
Hey,

Thanks for your prompt reply *Tim & luisza14*, i have gone through the 
documentation. From what i have understood:

When we get all objects from the queryset = User.objects.all() it cache the 
result and it is better to filter it from this result than hitting the db 
on every subsequent request. while when it does not have desired result it 
will hit the db and fetch it.

correct me if i am wrong. 


Well let say i have 1 million rows, is it advisable to work this same 
manner as it will be caching all 1million result?
 

On Monday, June 22, 2015 at 8:58:51 PM UTC+5:30, Paritosh Gupta wrote:
>
> Hello,
>
> Do advice me on:
>
> queryset = User.objects.all()
> user = get_object_or_404(pk=id)
>
>
>
> > Is it better to call the list in queryset and then apply filter or 
> directly use .filter() in the first step.
>
> > If so, when we call all the object frequently does it cache and from 
> cache we do filter or does it db everytime.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/bafe1f73-5245-4feb-9b8f-0b52a3609641%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Queryset Practice

2015-06-22 Thread Luis Zárate
Querysets are lazy,  so Model.objects.all().filter(...) execute a same
query that Model.objects.filter(...).all()  and Model.objects.filter(...).
For check this tray  in shell

str(Model.objects.all().filter(pk=1).query)

str(Model.objects.filter(pk=1).all().query)

str(Model.objects.filter(pk=1).query)


2015-06-22 10:32 GMT-06:00 Tim Graham :

> Have you had a look at the documentation?
>
> https://docs.djangoproject.com/en/stable/topics/db/optimization/#understand-querysets
>
> On Monday, June 22, 2015 at 11:28:51 AM UTC-4, Paritosh Gupta wrote:
>>
>> Hello,
>>
>> Do advice me on:
>>
>> queryset = User.objects.all()
>> user = get_object_or_404(pk=id)
>>
>>
>>
>> > Is it better to call the list in queryset and then apply filter or
>> directly use .filter() in the first step.
>>
>> > If so, when we call all the object frequently does it cache and from
>> cache we do filter or does it db everytime.
>>
>  --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> 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/6879eaf6-d906-40ff-8ff1-bed514621856%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CAG%2B5VyPS4NBuqqGx_D9OAiEBLyPjAq8QMWy%3DbAht1%2B3PDnNRZQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Queryset Practice

2015-06-22 Thread Tim Graham
Have you had a look at the documentation?
https://docs.djangoproject.com/en/stable/topics/db/optimization/#understand-querysets

On Monday, June 22, 2015 at 11:28:51 AM UTC-4, Paritosh Gupta wrote:
>
> Hello,
>
> Do advice me on:
>
> queryset = User.objects.all()
> user = get_object_or_404(pk=id)
>
>
>
> > Is it better to call the list in queryset and then apply filter or 
> directly use .filter() in the first step.
>
> > If so, when we call all the object frequently does it cache and from 
> cache we do filter or does it db everytime.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/6879eaf6-d906-40ff-8ff1-bed514621856%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Best Queryset Practice

2015-06-22 Thread Paritosh Gupta
Hello,

Do advice me on:

queryset = User.objects.all()
user = get_object_or_404(pk=id)



> Is it better to call the list in queryset and then apply filter or 
directly use .filter() in the first step.

> If so, when we call all the object frequently does it cache and from 
cache we do filter or does it db everytime.

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/0d1de3cd-af5b-4fb5-b4df-5efe114f9e4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.