这是我的模型.我想做的是在保存模型实例时生成一个新文件并覆盖现有文件:
class Kitten(models.Model):
claw_size = ...
license_file = models.FileField(blank=True, upload_to='license')
def save(self, *args, **kwargs):
#Generate a new license file overwriting any previous version
#and update file path
self.license_file = ???
super(Request,self).save(*args, **kwargs)
我看到很多关于如何上传文件的文档.但是,如何生成文件、将其分配给模型字段并让Django将其存储在正确的位置呢?