﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
3074	[bug] OneToOneField referencing a different app does not always register a Reverse Lookup.	nowell strite	Adrian Holovaty	"!OneToOneField does not register a Reverse Lookup when the relation references a different application. See the example below.

== Create project, application, and models ==

'''/project/appone/models.py'''
{{{
from django.db import models

class Foo(models.Model):
    w = models.CharField(maxlength=20)

class Bar(models.Model):
    x = models.CharField(maxlength=10)
    y = models.ManyToManyField(Foo)
}}}

'''/project/apptwo/models.py'''
{{{
from django.db import models
from project.appone.models import Bar

class Baz(models.Model):
    bar = models.OneToOneField(Bar)
}}}


== Setup test data ==
 * Add appone and apptwo to the INSTALLED_APPLICATIONS
 * Run python manage.py syncdb
 * Run python manage.py shell
{{{
>>> from appone.models import *
>>> from apptwo.models import *
>>> a = Foo()
>>> a.w = '1'
>>> a.save()

>>> b = Bar()
>>> b.x = '2'
>>> b.save()
>>> b.y = [a]

>>> c = Baz()
>>> c.bar = b
>>> c.save()
}}}
 * Next exit the shell environment to simulate a fresh environment
 * run python manage.py shell

'''This doesn't work'''
{{{
>>> from appone.models import Bar
>>> d = Bar.objects.all()[0]
>>> d.baz
Traceback (most recent call last):
  File ""<console>"", line 1, in ?
AttributeError: 'Bar' object has no attribute 'baz'

}}}

'''This works'''
{{{
>>> from appone.models import Bar
>>> d = Bar.objects.get(pk=1)
>>> d.baz
}}}"	defect	closed	Database layer (models, ORM)	0.95	normal	worksforme			Unreviewed	0	0	0	0	0	0
