auto compress product icons

This commit is contained in:
thomas girod
2024-09-14 21:51:35 +02:00
parent e2b42145e1
commit 79ef151ad3
6 changed files with 191 additions and 12 deletions

View File

@ -0,0 +1,37 @@
# Generated by Django 4.2.16 on 2024-09-14 18:02
from django.db import migrations
import core.fields
class Migration(migrations.Migration):
dependencies = [
("counter", "0021_rename_check_cashregistersummaryitem_is_checked"),
]
operations = [
migrations.AlterField(
model_name="product",
name="icon",
field=core.fields.ResizedImageField(
blank=True,
height=70,
force_format="WEBP",
null=True,
upload_to="products",
verbose_name="icon",
),
),
migrations.AlterField(
model_name="producttype",
name="icon",
field=core.fields.ResizedImageField(
blank=True,
force_format="WEBP",
height=70,
null=True,
upload_to="products",
),
),
]

View File

@ -37,6 +37,7 @@ from django_countries.fields import CountryField
from accounting.models import CurrencyField
from club.models import Club
from core.fields import ResizedImageField
from core.models import Group, Notification, User
from core.utils import get_start_of_semester
from sith.settings import SITH_COUNTER_OFFICES, SITH_MAIN_CLUB
@ -208,7 +209,9 @@ class ProductType(models.Model):
name = models.CharField(_("name"), max_length=30)
description = models.TextField(_("description"), null=True, blank=True)
comment = models.TextField(_("comment"), null=True, blank=True)
icon = models.ImageField(upload_to="products", null=True, blank=True)
icon = ResizedImageField(
height=70, force_format="WEBP", upload_to="products", null=True, blank=True
)
# priority holds no real backend logic but helps to handle the order in which
# the items are to be shown to the user
@ -250,8 +253,13 @@ class Product(models.Model):
purchase_price = CurrencyField(_("purchase price"))
selling_price = CurrencyField(_("selling price"))
special_selling_price = CurrencyField(_("special selling price"))
icon = models.ImageField(
upload_to="products", null=True, blank=True, verbose_name=_("icon")
icon = ResizedImageField(
height=70,
force_format="WEBP",
upload_to="products",
null=True,
blank=True,
verbose_name=_("icon"),
)
club = models.ForeignKey(
Club, related_name="products", verbose_name=_("club"), on_delete=models.CASCADE