add image to model

This commit is contained in:
zakhy 2024-12-17 13:06:21 +07:00
parent 56773eea67
commit 12a8d1ec7e

View File

@ -19,6 +19,7 @@ class BackgroundVideo(models.Model):
validators=[FileExtensionValidator(allowed_extensions=["webm"])],
blank=True, null=True
)
image = models.ImageField(upload_to='videos/images/', blank=True, null=True)
def __str__(self):
return self.mp4_file.name.split('.')[0]
@ -32,5 +33,9 @@ class BackgroundVideo(models.Model):
os.remove(self.mp4_file.path)
except FileNotFoundError:
error_logger.error(traceback.format_exc())
try:
os.remove(self.image.path)
except FileNotFoundError:
error_logger.error(traceback.format_exc())
super().delete(*args, **kwargs)