diff --git a/core/migrations/0045_quickuploadimage.py b/core/migrations/0045_quickuploadimage.py index 83edcc65..30091c72 100644 --- a/core/migrations/0045_quickuploadimage.py +++ b/core/migrations/0045_quickuploadimage.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.20 on 2025-04-06 09:55 +# Generated by Django 4.2.20 on 2025-04-10 08:14 import django.db.models.deletion from django.conf import settings @@ -25,7 +25,14 @@ class Migration(migrations.Migration): ), ("uuid", models.UUIDField(db_index=True, unique=True)), ("name", models.CharField(max_length=100)), - ("image", models.ImageField(upload_to="upload/%Y/%m/%d")), + ( + "image", + models.ImageField( + height_field="height", + upload_to="upload/%Y/%m/%d", + width_field="width", + ), + ), ( "created_at", models.DateTimeField(auto_now_add=True, verbose_name="created at"), diff --git a/core/models.py b/core/models.py index d69fc92c..198a38b6 100644 --- a/core/models.py +++ b/core/models.py @@ -1114,7 +1114,9 @@ class QuickUploadImage(models.Model): uuid = models.UUIDField(unique=True, db_index=True) name = models.CharField(max_length=IMAGE_NAME_SIZE, blank=False) - image = models.ImageField(upload_to="upload/%Y/%m/%d") + image = models.ImageField( + upload_to="upload/%Y/%m/%d", width_field="width", height_field="height" + ) uploader = models.ForeignKey( "User", related_name="quick_uploads", @@ -1155,11 +1157,13 @@ class QuickUploadImage(models.Model): name=name, image=file, uploader=uploader, - width=width, - height=height, size=file.size, ) + def delete(self, *args, **kwargs): + self.image.delete(save=False) + return super().delete(*args, **kwargs) + class LockError(Exception): """There was a lock error on the object."""