To access a db object, there is a get() method and a get_or_create()
method. I often need to test for an object or get it without failing
if it doesn't exist. Of course I could do something like

 exists = Foo.objects.filter(id=id).count() == 1

or

 try:
     foo = Foo.objects.get(id=id)
     ...
 except: Foo.DoesNotExist:
     foo = None
 ...

or

 for foo in Foo.objects.filter(id=id)[:1]: ...

but I wonder whether it might be useful to add a method get_or_none()
and another exists() method to the objects object. What do you think?

-- 
Stefan Matthias Aust

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to