On 17 Dec, 16:08, Darthmahon <cpma...@gmail.com> wrote:
> Why not create your own function then and just put the try or except
> code in that? That way it'll only be one line.

Yup. Using model.Manager i.e.:

class MyManager(models.Manager):
    def get_or_blank(self, pk_val):
        try:
            m = super(self.__class__, self).get_query_set().get
(pk=pk_val)
        except self.model.DoesNotExist:
            m = self.model()
        return m

then you'd need, in each model def:
objects = MyManager()

Now you can do:
s = SomeModel.objects.get_or_blank(35)




--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to