views:

304

answers:

2

Okay, how would I do this?

class Example(models.Model):
  parent_example = models.ForeignKey(Example)

I want to have a model have a foreign key reference to itself. When I try to create this I get a django validation error that Example is not yet defined.

+2  A: 

Yes, just do this:

class Example(models.Model):
  parent_example = models.ForeignKey('self')
Joe Holloway
+8  A: 

You should use

models.ForeignKey('self')

as mentioned here.

ohnoes