From 4b367944b92c5a7b32d98e0f22a019fb4127fed9 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Sat, 21 Jun 2025 19:42:16 +0300 Subject: [PATCH] Features: 1) Update `product.slug` to use `AutoSlugField` with adjusted `populate_from` order in migrations and model; Fixes: 1) None; Extra: Refactor `product.slug` field declaration for improved readability in `models.py`. --- core/migrations/0031_alter_product_slug.py | 26 ++++++++++++++++++++++ core/models.py | 7 +++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 core/migrations/0031_alter_product_slug.py diff --git a/core/migrations/0031_alter_product_slug.py b/core/migrations/0031_alter_product_slug.py new file mode 100644 index 00000000..cebf2052 --- /dev/null +++ b/core/migrations/0031_alter_product_slug.py @@ -0,0 +1,26 @@ +# Generated by Django 5.2 on 2025-06-21 16:40 + +import django_extensions.db.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0030_alter_category_slug"), + ] + + operations = [ + migrations.AlterField( + model_name="product", + name="slug", + field=django_extensions.db.fields.AutoSlugField( + allow_unicode=True, + blank=True, + editable=False, + null=True, + populate_from=("name", "brand__slug", "category__slug", "uuid"), + unique=True, + ), + ), + ] diff --git a/core/models.py b/core/models.py index 5b436d03..47336b51 100644 --- a/core/models.py +++ b/core/models.py @@ -358,7 +358,12 @@ class Product(ExportModelOperationsMixin("product"), NiceModel): verbose_name=_("part number"), ) slug: str | None = AutoSlugField( # type: ignore - populate_from=("uuid", "category__slug", "brand__slug", "name"), + populate_from=( + "name", + "brand__slug", + "category__slug", + "uuid", + ), allow_unicode=True, unique=True, editable=False,