Merge branch 'main' into storefront-nuxt
This commit is contained in:
commit
5f50281029
4 changed files with 33 additions and 3 deletions
|
|
@ -204,7 +204,7 @@ class AttributeAdmin(FieldsetsMixin, ActivationActionsMixin, ModelAdmin): # typ
|
||||||
readonly_fields = ("uuid", "modified", "created")
|
readonly_fields = ("uuid", "modified", "created")
|
||||||
autocomplete_fields = ["categories", "group"]
|
autocomplete_fields = ["categories", "group"]
|
||||||
|
|
||||||
general_fields = ["is_active", "name", "value_type"]
|
general_fields = ["is_active", "name", "value_type", "is_filterable"]
|
||||||
relation_fields = ["group", "categories"]
|
relation_fields = ["group", "categories"]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ class CategoryType(DjangoObjectType):
|
||||||
):
|
):
|
||||||
distinct_vals = (
|
distinct_vals = (
|
||||||
AttributeValue.objects.annotate(value_length=Length("value"))
|
AttributeValue.objects.annotate(value_length=Length("value"))
|
||||||
.filter(attribute=attr, product__category=self, value_length__lte=30)
|
.filter(attribute=attr, attribute__is_filterable=True, product__category=self, value_length__lte=30)
|
||||||
.values_list("value", flat=True)
|
.values_list("value", flat=True)
|
||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
|
||||||
26
core/migrations/0043_attribute_is_filterable_and_more.py
Normal file
26
core/migrations/0043_attribute_is_filterable_and_more.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Generated by Django 5.2 on 2025-09-22 11:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("core", "0042_attribute_name_fa_ir_attribute_name_he_il_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="attribute",
|
||||||
|
name="is_filterable",
|
||||||
|
field=models.BooleanField(
|
||||||
|
default=True,
|
||||||
|
help_text="designates whether this attribute can be used for filtering or not",
|
||||||
|
verbose_name="is filterable",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name="attribute",
|
||||||
|
unique_together={("name", "group")},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -81,7 +81,11 @@ class CategoryDetailSerializer(ModelSerializer):
|
||||||
|
|
||||||
request = self.context.get("request")
|
request = self.context.get("request")
|
||||||
user = getattr(request, "user", AnonymousUser())
|
user = getattr(request, "user", AnonymousUser())
|
||||||
attrs_qs = obj.attributes.all() if user.has_perm("view_attribute") else obj.attributes.filter(is_active=True)
|
attrs_qs = (
|
||||||
|
obj.attributes.filter(is_filterable=True)
|
||||||
|
if user.has_perm("view_attribute")
|
||||||
|
else obj.attributes.filter(is_active=True, is_filterable=True)
|
||||||
|
)
|
||||||
attributes = list(attrs_qs)
|
attributes = list(attrs_qs)
|
||||||
|
|
||||||
attr_ids = [a.id for a in attributes]
|
attr_ids = [a.id for a in attributes]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue