On 10 October 2012 10:29, Anssi Kääriäinen <anssi.kaariai...@thl.fi> wrote: > On 9 loka, 20:15, ptone <pres...@ptone.com> wrote: >> Unsurprisingly - this has come up before: >> >> Earlier >> discussionhttps://groups.google.com/forum/?fromgroups=#!topic/django-developers... >> >> tickets:https://code.djangoproject.com/ticket/17546https://code.djangoproject.com/ticket/2659https://code.djangoproject.com/ticket/11352 >> >> All the ticket's were wontfixed > > OK, it seems .get_or_none() method is out. I can see the point of that > decision, there are a lot of similar methods that could be added using > the convenience argument (like .first() in conjunction > with .latest()). > > But, how about .get() with __default kwarg?
My experience is that the _only_ default you will ever use in this situation is None. I think this is because QuerySet.get() returns a full blown object. A default object would have to be some other full blown object, and it's unlikely that you'll be in the situation where you want to find an object but some other object is an acceptable alternative. You might want to find an object and create it if it does not exist -- this is why get_or_create is a useful API :-) Dictionaries by contrast can contain 'primitive' types as values and they have acceptable and varying 'default' values -- 0, '', [] etc. Many uses of get-with-default could be replaced with a defaultdict. FWIW, get_or_none() seems useful to me but I can live without it. Cheers, mwh -- 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 django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.