Features: 1) Add AutoSlugField "slug" to Category model with unique and auto-populating behavior; 2) Include "slug" field in CategoryFilter and relevant serializers (detail and simple); 3) Add "slug" to GraphQL object type for categories;
Fixes: None; Extra: Add migration for new "slug" field in Category model.
This commit is contained in:
parent
6678b84de2
commit
71cb0fc2db
6 changed files with 31 additions and 0 deletions
|
|
@ -251,6 +251,7 @@ class CategoryFilter(FilterSet):
|
|||
uuid = UUIDFilter(field_name="uuid", lookup_expr="exact")
|
||||
name = CharFilter(field_name="name", lookup_expr="icontains")
|
||||
parent_uuid = UUIDFilter(field_name="parent__uuid", lookup_expr="exact")
|
||||
slug = CharFilter(field_name="slug", lookup_expr="exact")
|
||||
|
||||
order_by = OrderingFilter(
|
||||
fields=(
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ class CategoryType(DjangoObjectType):
|
|||
"attributes",
|
||||
"children",
|
||||
"name",
|
||||
"slug",
|
||||
"description",
|
||||
"image",
|
||||
"min_max_prices",
|
||||
|
|
|
|||
19
core/migrations/0022_category_slug.py
Normal file
19
core/migrations/0022_category_slug.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 5.2 on 2025-05-21 09:35
|
||||
|
||||
import django_extensions.db.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('core', '0021_rename_name_ar_ar_attribute_name_ar_ar_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='category',
|
||||
name='slug',
|
||||
field=django_extensions.db.fields.AutoSlugField(allow_unicode=True, blank=True, editable=False, null=True,
|
||||
populate_from=('uuid', 'name'), unique=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -198,6 +198,14 @@ class Category(NiceModel, MPTTModel):
|
|||
verbose_name=_("category description"),
|
||||
)
|
||||
|
||||
slug = AutoSlugField(
|
||||
populate_from=("uuid", "name"),
|
||||
allow_unicode=True,
|
||||
unique=True,
|
||||
editable=False,
|
||||
null=True,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ class CategoryDetailSerializer(ModelSerializer):
|
|||
"markup_percent",
|
||||
"filterable_attributes",
|
||||
"children",
|
||||
"slug",
|
||||
"created",
|
||||
"modified",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class CategorySimpleSerializer(ModelSerializer):
|
|||
"uuid",
|
||||
"name",
|
||||
"image",
|
||||
"slug",
|
||||
"children",
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue