#11448: Defining relationships after querying a model does not add a reverse
lookup
to the referenced model
------------------------------------------+---------------------------------
Reporter: Dennis Kaarsemaker | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 |
------------------------------------------+---------------------------------
Ok, that sounds vague but I don't know how to better describe it.
Basically it boils down to having this in models.py:
{{{
from django.db import models
import os
class c1(models.Model):
name = models.CharField("Name", max_length=30)
default_c1 = c1.objects.get(name="non_existant")
class c2(models.Model):
other = models.ForeignKey(c1, default=default_c1)
}}}
Querying c1 later with c1.objects.filter(c2__pk=0) will fail:
FieldError: Cannot resolve keyword 'c2' into field. Choices are: id, name
Minimal testcase project attached (models.py is slightly bigger than
above). You can reproduce the problem with:
{{{
# Create the database (clobbers test.db in the current dir)
./manage.py syncdb
# See that without querying in between it works
echo -e "from proj1.app1.models import c1\nc1.objects.filter(c2__pk=0)" |
./manage.py shell
# See that with querying in between it fails
echo -e "from proj1.app1.models import c1\nc1.objects.filter(c2__pk=0)" |
BREAK_ME=1 ./manage.py shell
}}}
Found on 1.0.2, confirmed with trunk (fresh checkout, less than 30 minutes
ago)
--
Ticket URL: <http://code.djangoproject.com/ticket/11448>
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
-~----------~----~----~----~------~----~------~--~---