There is an example of this given here:
http://www.djangoproject.com/documentation/models/mutually_referential/
It hasn't been updated to reflect magic removal changes, but seems pretty straightforward:
class Parent( models.Model ):
name = models.CharField(maxlength=100, core=True)
bestchild = models.ForeignKey("Child", null=True, related_name="favoured_by")
class Admin:
pass
class Child( models.Model ):
name = models.CharField(maxlength=100)
parent = models.ForeignKey(Parent)
class Admin:
pass
When playing with these models in the shell, everything seems to work fine. When I use the admin interface and click to add a child I get:
'bool' object has no attribute 'get'
with the full stack trace:
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response
74. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py" in _checklogin
55. return view_func(request, *args, **kwargs)
File "/home/bryan/web/django_src/django/views/decorators/cache.py" in _wrapped_view_func
40. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/main.py" in add_stage
246. manipulator = model.AddManipulator()
File "/home/bryan/web/django_src/django/db/models/manipulators.py" in __init__
75. self.fields.extend(f.get_manipulator_fields(self.opts, self, self.change, fol))
File "/usr/lib/python2.4/site-packages/django/db/models/related.py" in get_manipulator_fields
116. if follow.get(f.name, False):
AttributeError at /admin/organizer/child/add/
'bool' object has no attribute 'get'
Adding a Parent works until you try and add the bestchild attribute.