I've got a Django class like this:
class Breakfast(m.Model):
# egg = m.OneToOneField(Egg)
...
class Egg(m.Model):
breakfast = m.OneToOneField(Breakfast, related_name="egg")
Is it possible to have breakfast.egg == None
if there is no Egg
related to the Breakfast
?
Edit: Forgot to mention: I'd rather not change the related_name
to something like related_name="_egg"
, then have something like:
@property
def egg(self):
try: return self.egg
except ...: return None
Because I use the name egg
in queries, and I'd rather not have to change the queries to using _egg
.