Created
October 30, 2009 01:43
-
-
Save zachseifts/222011 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person(models.Model): | |
name = models.CharField(_('name'), max_length=128) | |
parent = models.ForeignKey('self') | |
# parent, assuming this person is spontaneously created | |
fred = Person(name='Fred') | |
# me and my brothers | |
zach = Person.objects.get_or_create(name='Zach', parent=fred) | |
trevor = Person.objects.get_or_create(name='Trevor', parent=fred) | |
austin = Person.objects.get_or_create(name='Austin', parent=fred) | |
zach.parent_set.all() | |
# [fred] | |
austin.parent_set.all() | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment