﻿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
1648	How to ForeignKey to itself	alankila	Adrian Holovaty	"Let's assume the following Model definition, which isn't necessarily useful by itself but illustrates the problem:
{{{
class Foo(meta.Model):
    parent = meta.ForeignKey(Foo, null=True, blank=True)
}}}
We hit a Python limitation: It is not possible to refer to the class name Foo during its definition. What should be done to resolve this?

I attempted to remedy by doing the following, but it didn't work:
{{{
class Foo(meta.Model):
    pass
Foo.parent = meta.ForeignKey(Foo, null=True, blank=True)
}}}
There is no parent field in a model thus defined.

1) This should work, shouldn't it? Why doesn't it work?

2) Is there a better way to construct self-referencing models?"	defect	closed	Database layer (models, ORM)		normal	worksforme			Unreviewed	0	0	0	0	0	0
