diff --git a/src/purchase/models.py b/src/purchase/models.py index dd4e8fa..38a399a 100644 --- a/src/purchase/models.py +++ b/src/purchase/models.py @@ -1,5 +1,7 @@ from __future__ import annotations +import hashlib + from django.db import models from django.db.models import Avg, Count, F, Sum from django.db.models.functions import Coalesce @@ -102,6 +104,12 @@ class Product(Model): def natural_key(self): return (self.name,) + @property + def color_hue(self): + return int( + hashlib.sha256(bytes(self.name, encoding="utf-8")).hexdigest()[:2], base=16 + ) + def save(self, *args, **kwargs): super().save() if not self.image: diff --git a/src/purchase/static/purchase/css/basket_form.css b/src/purchase/static/purchase/css/basket_form.css new file mode 100644 index 0000000..725ad75 --- /dev/null +++ b/src/purchase/static/purchase/css/basket_form.css @@ -0,0 +1,10 @@ +.product-img-placeholder { + aspect-ratio: 1/1; + font-size: 6em; + display: flex; + flex-direction: column; + justify-content: space-around; +} +.product-img-placeholder span { + text-align: center; +} diff --git a/src/purchase/templates/purchase/basket_form.html b/src/purchase/templates/purchase/basket_form.html index 5c6ef93..db5094e 100644 --- a/src/purchase/templates/purchase/basket_form.html +++ b/src/purchase/templates/purchase/basket_form.html @@ -1,6 +1,10 @@ {% extends "common/base.html" %} +{% load static %} {% load i18n %} {% load crispy_forms_tags purchase %} +{% block extrahead %} + +{% endblock %} {% block content %} {% if object %}

{{ object }} {{ object.price|currency }}

diff --git a/src/purchase/templates/purchase/snippets/basket_item.html b/src/purchase/templates/purchase/snippets/basket_item.html index 3d860d7..affd6d1 100644 --- a/src/purchase/templates/purchase/snippets/basket_item.html +++ b/src/purchase/templates/purchase/snippets/basket_item.html @@ -3,6 +3,13 @@
{% if product.image %} + {% else %} +
+ + {{ product.name|slice:"1" }} + +
{% endif %}

{{ product.name }}