Re: Django Model - create a filter and use it as argument

6 views
Skip to first unread message
Message has been deleted

akaariai

unread,
Apr 4, 2012, 6:08:28 PM4/4/12
to Django users
On Apr 5, 1:00 am, Ivo Marcelo Leonardi Zaniolo <imarcel...@gmail.com>
wrote:
> Hi there,
>
> I'm need to pass a QuerySet as an argument, like a function pointer that
> will be
> evaluate in other time. Somebody has one idea how I can do this?
> I dont want to create a "box" method to encapsulate it.
>
> So, can anyone help me?

QuerySets are evaluated only when accessed. So, you can just do:

def method(qs):
qs = qs.filter(somethingelse=bar)
list(qs)

qs = SomeModel.objects.filter(something=foo)
method(qs)

The queryset will be evaluated at list(qs) time.

- Anssi
Reply all
Reply to author
Forward
Message has been deleted
0 new messages