几个月来我一直有一个间歇性的错误,我被卡住了!帮助表示赞赏。
class ContentFile(models.Model):
"""
Represents the metadata for a single document.
"""
name = models.CharField(max_length=200)
set = models.ForeignKey(Set, related_name='contentfile_set', on_delete=models.CASCADE)
location = models.FileField(upload_to=get_content_file_upload_path)
class Meta:
app_label = 'ProtocolManager'
unique_together = ('set', 'location')
def __str__(self):
return f"File {self.name} at location {str(self.location)} attached to {self.set}"
@receiver(models.signals.post_delete, sender=ContentFile)
def delete_file(sender, instance, *args, **kwargs):
"""
Delete orphaned file once last ContentFile is removed.
"""
log.info(f"Checking {instance.location} for existing ContentFile")
if instance.location:
from django.db import connection
from django.db import reset_queries
reset_queries()
files_queryset = ContentFile.objects.filter(location=instance.location)
if …Run Code Online (Sandbox Code Playgroud) python django amazon-web-services amazon-rds django-rest-framework