我正试图建立一个系统,使用户能够上载齐pfile,然后利用“空洞”信号提取。
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.close()