Possible Duplicate:
Can I have a Django model that has a foreign key reference to itself?
I want to implement a simple folder-file like structure in my Django app. So I have a model for storing folders, but I also would like to store relation between this folder and parent folder. The simplified version of model would look like following:
class mFolder(models.Model):
name = models.CharField(max_length=50)
parentFolder = models.ForeignKey(mFolder, unique=False, related_name="childrenFolders")
However this is not possible, beacause mFolder is not declared yet.
Is there any simple solution for that problem?
Thanks for your help in advance.
Should be 'self':
parentFolder = models.ForeignKey('self', unique=False, related_name="childrenFolders")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With