如何创建这样的东西:
如果我创建MyFile
对象,Document
对象将自动创建。(rootfile
应该ForeignKey
是MyFile
)
class MyFile(models.Model):
user = models.ForeignKey(User)
path = models.FileField(upload_to="files")
class Document(models.Model):
rootfile = models.ForeignKey(MyFile)
user = models.ForeignKey(User,related_name='doc_owner')
title = models.CharField(max_length=255)
description = models.TextField()
content = models.TextField()