#27242: Add get_object_or_none to django.shortcuts
------------------------------+-------------------------------------
     Reporter:  arogachev     |      Owner:  nobody
         Type:  New feature   |     Status:  new
    Component:  Core (Other)  |    Version:  master
     Severity:  Normal        |   Keywords:  object, model, shortcut
 Triage Stage:  Unreviewed    |  Has patch:  0
Easy pickings:  0             |      UI/UX:  0
------------------------------+-------------------------------------
 I think quite often we need to find object of certain model and return
 `None` if it does not exist. I suggest to add this to `django.shortcuts`:

 {{{#!python
 def get_object_or_none(klass, *args, **kwargs):
     queryset = _get_queryset(klass)
     try:
         return queryset.get(*args, **kwargs)
     except queryset.model.DoesNotExist:
         return None
 }}}

 Yes, we can easily create this in our own code, but maybe consider to add
 this to the core?

--
Ticket URL: <https://code.djangoproject.com/ticket/27242>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.e56412208f671c2e06ae2f15cf8b3207%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to