On Mon, Mar 30, 2009 at 6:34 PM, famousactress <[email protected]>wrote:

>
> Ooooh. Thanks, Karen.. This is exactly what I wanted. Although I still
> wouldn't mind a function for when I'm not planning to immediately
> create the object. Thanks for the tip!
>
> On Mar 30, 3:27 pm, Karen Tracey <[email protected]> wrote:
> > I think you missed get_or_create:
> >
> > http://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-cre...
> >
> > Karen
>
> Alex,
>
> The problem with that is that it's not DRY enough for my taste. Before
> doing that, I'd create a method (sorta like the only() one) that just
> does that..
>
> def queryset_getNice(self, **kwargs):
>  try
>    return self.get(kwargs)
>  except Model.DoesNotExist:
>    return None
>
> Right? Why write the same boilerplate code all over the place?
>
> Phill
> >
>
Feel free to wrap it up into a utility function for yourself.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to