#12708: Django raises DoesNotExist when consulting an empty ForeignKey field
------------------------------------------+---------------------------------
Reporter: lsaffre | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Keywords: ForeignKey DoesNotExist | Stage: Unreviewed
Has_patch: 0 |
------------------------------------------+---------------------------------
{{{
"""
Django raises DoesNotExist when consulting an empty ForeignKey field
We create an Order without a Journal::
>>> o = Order()
>>> print o.journal
None
>>> o.save()
This works only because `Order.journal` has `null=True`.
In fact I want the `save()` method to complain if `journal` is empty,
so I remove `null=True` from the field definition.
>>> o = Order2()
>>> print o.journal
None
The above line raises a DoesNotExist exception. Django should raise
an exception only when I try to save the instance, not already when
I want to see the value of `journal`!
"""
from django.db import models
class Journal(models.Model):
pass
class Order(models.Model):
journal = models.ForeignKey(Journal,null=True)
class Order2(models.Model):
journal = models.ForeignKey(Journal)
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/12708>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en.