When I say id=None, it returns all of the items. My guess is that if a
field is set to none, it just ignores that argument. However filter(
id=-1) does the trick. Thanks for the tip.

However django should probably have a way to do this without pinging
the db (i think :)

- Steve

On 10/27/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> On Fri, 2006-10-27 at 00:06 -0700, Steve Wedig wrote:
> > I'm interested in returning a Null (empty) query set. I guess this is
> > like the Null Object pattern. So it has to be a QuerySet implements
> > the interface (.count, .all, etc) that always returns nothing.
> >
> > Does anyone know how to do this?
>
> The immediate thing that comes to mind is to construct a query that is
> guaranteed to fail. Suppose you have a field called "my_field" in your
> model. It can be any field you like. Then the following should always
> return an empty QuerySet:
>
>         MyModel.objects.filter(my_field = None)
>
> You might think that this would return values where my_field was NULL in
> the database, but to do that you would need to use
> filter(my_field__isnull = True), which is slightly different. So the
> first example will always select no rows and still return a QuerySet.
>
> Regards,
> Malcolm
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to