Re: _QuerySet.first()
On Fri, 25 Apr 2008 05:59:49 -0700, Jan Oberst wrote: >> Does this differ from just using a slice does? >> >>foo = MyModel.objects.all()[0] >> >> > latest() involves an automated ORDER BY after the field you specified in > Meta's get_latest_by. So it would do the same as a slice[0], if you > sorted it correctly. > I see. But then one could argue that latest() is a little redundant here, as well. I guess it has already been in wide use for awhile, and removing it would introduce backward incompatibility. I was simply wondering if having a reverse shortcut method would make sense. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@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-developers?hl=en -~--~~~~--~~--~--~---
Re: _QuerySet.first()
> Does this differ from just using a slice does? > >foo = MyModel.objects.all()[0] > latest() involves an automated ORDER BY after the field you specified in Meta's get_latest_by. So it would do the same as a slice[0], if you sorted it correctly. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@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-developers?hl=en -~--~~~~--~~--~--~---
Re: _QuerySet.first()
On Fri, Apr 25, 2008 at 2:17 PM, Patrick J. Anderson <[EMAIL PROTECTED]> wrote: > Well, then you could also use: > > foo = MyModel.objects.all()[-1] > > Wouldn't '_Queryset.latest()' be faster than slicing a big queryset list? It's slicing on the RDBMS side unless you already evaluated the query. -- Patryk Zawadzki PLD Linux Distribution --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@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-developers?hl=en -~--~~~~--~~--~--~---
Re: _QuerySet.first()
On Fri, 25 Apr 2008 06:57:06 -0500, Tim Chase wrote: >> I poked around 'django.db.model.query' this morning and noticed that >> '_QuerySet' class has 'latest(self, field_name=None)' method. I was >> wondering if adding 'first(self, field_name=None)' had been considered >> before. >> >> It seems that could be a useful shortcut in some instances. > > Does this differ from just using a slice does? > >foo = MyModel.objects.all()[0] > > which is exactly what what get() does (though IIRC, it also does some > checks to ensure that one-and-only-one record comes back). > > -tim > > > > Well, then you could also use: foo = MyModel.objects.all()[-1] Wouldn't '_Queryset.latest()' be faster than slicing a big queryset list? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@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-developers?hl=en -~--~~~~--~~--~--~---
Re: _QuerySet.first()
> I poked around 'django.db.model.query' this morning and noticed that > '_QuerySet' class has 'latest(self, field_name=None)' method. I was > wondering if adding 'first(self, field_name=None)' had been considered > before. > > It seems that could be a useful shortcut in some instances. Does this differ from just using a slice does? foo = MyModel.objects.all()[0] which is exactly what what get() does (though IIRC, it also does some checks to ensure that one-and-only-one record comes back). -tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@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-developers?hl=en -~--~~~~--~~--~--~---
_QuerySet.first()
Hi! I poked around 'django.db.model.query' this morning and noticed that '_QuerySet' class has 'latest(self, field_name=None)' method. I was wondering if adding 'first(self, field_name=None)' had been considered before. It seems that could be a useful shortcut in some instances. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@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-developers?hl=en -~--~~~~--~~--~--~---