如何访问path_after
信号中的字段?
楷模:
class Store(models.Model):
user = models.ForeignKey(User)
path = models.FileField(upload_to="src")
path_after = models.FileField(upload_to="files",blank=True, null=True)
class Document(models.Model):
rootfile = models.ForeignKey(Store)
content = models.TextField()
信号:
@receiver(post_save, sender=Store)
def my_handler(sender, **kwargs):
if kwargs['created']:
document = Document()
document.rootfile = kwargs['instance']
#how to open file from path_after field?
text_file = open("path_after", "r")
document.content = #should be text from path_after file, this is TextField
document.save()