> Is there a particular reason why using a related OneToOneField raises
> DoesNotExist instead of returning None?
>
> | class Person( Model ):
> |    pass
> |
> | class Pet( Model ):
> |    owner = OneToOneField( Person )
> |
> | # Assuming "joe" exists as a Person
> | >>> kitty = joe.pet
> | DoesNotExist: Pet matching query does not exist.

I have the same problem as TallFurryMan.  In this situation, kitty
should be None, rather than an exception being thrown, since the
related object not existing is a valid, non-exceptional condition, and
this would bring symmetry between OneToOneField and ForeignKey.  It
also would enable more conveniently checking if such an object does or
doesn't exist, ie:

   if joe.pet == None and some_other_condition():  do_stuff()

Rather than having to code such an expression using a try/rescue.

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