Re: Creating an empty queryset
On 12/27/06, medhat <[EMAIL PROTECTED]> wrote: Is there a way to create an empty queryset?! Let's say I have a manager to return all the items with the given tags, and I want to return "no items" if one of the given tags does not exist. Right now I return an empty list, but this causes an error in generic views. Is there a way to create an empty QuerySet object without hitting the database? I just had to do this the other day, and I ended up doing a hack like this: MyModel.objects.extra(where=['1=0']) That still hits the database, though. I'm not aware of a way to get an empty QuerySet without hitting the database. Maybe we should add one? Adrian -- Adrian Holovaty holovaty.com | djangoproject.com --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating an empty queryset
On 12/27/06, medhat <[EMAIL PROTECTED]> wrote: ... Right now I return an empty list, but this causes an error in generic views. I think you want allow_empty=True. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating an empty queryset
I would strongly second that. This seems to have fallen somewhat dead, though. Any thoughts?; anyone in favor of it?; anyone know of any reasons not to do it? Adam On Dec 27, 2006, at 1:42 PM, Adrian Holovaty wrote: > > On 12/27/06, medhat <[EMAIL PROTECTED]> wrote: >> Is there a way to create an empty queryset?! Let's say I have a >> manager >> to return all the items with the given tags, and I want to return "no >> items" if one of the given tags does not exist. Right now I return an >> empty list, but this causes an error in generic views. Is there a way >> to create an empty QuerySet object without hitting the database? > > I just had to do this the other day, and I ended up doing a hack > like this: > >MyModel.objects.extra(where=['1=0']) > > That still hits the database, though. I'm not aware of a way to get an > empty QuerySet without hitting the database. Maybe we should add one? > > Adrian > > -- > Adrian Holovaty > holovaty.com | djangoproject.com > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating an empty queryset
Adam Seering schrieb: > I would strongly second that. This seems to have fallen somewhat > dead, though. Any thoughts?; anyone in favor of it?; anyone know of > any reasons not to do it? +1 from me. I have already missed it several times. The "where 1=0 solution" looks stupid. And the changed implementation of QuerySet.in() also needs this (and uses where 1=0). Michael -- noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg - Tel +49-911-9352-0 - Fax +49-911-9352-100 http://www.noris.de - The IT-Outsourcing Company --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating an empty queryset
On 1/10/07, Michael Radziej <[EMAIL PROTECTED]> wrote: > > Adam Seering schrieb: > > I would strongly second that. This seems to have fallen somewhat > > dead, though. Any thoughts?; anyone in favor of it?; anyone know of > > any reasons not to do it? > > +1 from me. I have already missed it several times. The "where > 1=0 solution" looks stupid. And the changed implementation of > QuerySet.in() also needs this (and uses where 1=0). I'm +1 on adding a function for adding an empty queryset. Now, if only a patch would materialize out of the ether... :-) As for the '1=0' being stupid (and in() requiring it); agreed. 'where in ()' and 'where false' don't work on all DB backends, and it's non-trivial to optimize the logic chain to remove the need for the dumb clause. Any suggestions on better ways to represent this are greatfully accepted. Patches are even more greatfully accepted. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating an empty queryset
The patch is in http://code.djangoproject.com/ticket/3283 -- Thanks, Medhat --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating an empty queryset
On 1/11/07, medhat <[EMAIL PROTECTED]> wrote: > > The patch is in http://code.djangoproject.com/ticket/3283 Remember - no patch is complete without unit tests and documentation... Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating an empty queryset
Well, the patch now has documentation and tests. -- Thanks, Medhat --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---