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

Reply via email to