On Jun 24, 6:36 pm, Xavier Ordoquy <xordo...@linovia.com> wrote:
> Hi,
>
> I'm banging my head against the wall with an issue in get_query_set.
>
> I'm using django 1.2.1 and I'd like to filter the queryset results through a 
> date within get_query_set.
> However, I noticed that with the dev. server or gunicorn, the get_query_set 
> is only called on the first request.
>
> This manager is called from a queryset passed to a generic function so unless 
> those functions have builtin cache, I don't understand why the get_query_set 
> is only called on the first request.
> Has anyone an idea why this happens ?

>From your description, it sounds like you're doing something like
this:

    def my_function(queryset=MyModel.objects.all())
         return queryset.filter(whatever=whatever)

This is a standard Python gotcha, nothing to do with Django: never use
a mutable variable as a default parameter to a function. It is
executed *when the function is first defined*, not when it's called.
Use 'queryset=None' instead and set the default within the function.

If this isn't what you're doing, you need to show some actual code.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to