Thursday, July 5, 2012

RE: [] Re: queryset caching - without caching middleware

>Could you show where and how you are executing the query? If the
>queryset is a global, and does not go out of scope at the end of the
>request, then reusing the queryset will not cause the queryset to be
>re-evaluated.
>
>Eg, in this example, categories is a global outside of the view, and
>once evaluated, will not be re-evaluated just because you used it in a
>view.
>
>categories = Category.objects.all()
>
>def index(request):
> return render_to_response('index.html': { 'categories': categories })
>
>When querysets are executed is documented here:
>
>https://docs.djangoproject.com/en/1.4/ref/models/querysets/#when-querysets-are-evaluated


yep, global caught me.
I have a class:

class table(object):
queryset = Category.objects.all()
column1 = ...
column2 = ...

def render(self):
return '<table>...'

in a view I am doing:

tbl = table()
# somtimes adding filters
tbl.queryset = tbl.queryset.filter(...)


I want to create a html table like "forms" in django

Is it enough to call the all() method on the queryset in my rendering method to get the queryset query the db again?

regards

Henrik

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate