django signals, how to use “instance”
问题 I am trying to create a system which enables user to upload a zipfile, and then extract it using post_save signal. class Project: .... file_zip=FileField(upload_to='projects/%Y/%m/%d') @receiver(post_save, sender=Project) def unzip_and_process(sender, **kwargs): #project_zip = FieldFile.open(file_zip, mode='rb') file_path = sender.instance.file_zip.path with zipfile.ZipFile(file_path, 'r') as project_zip: project_zip.extractall(re.search('[^\s]+(?=\.zip)', file_path).group(0)) project_zip