Skip to content

Commit

Permalink
Fix filtering products by category, subcategory, producer, components…
Browse files Browse the repository at this point in the history
…, tags and promotions; add new fields, ordering options and inlines to the Admin panel for categories, subcategories, components, tags, producers, promotions, coupons and products; update tests
  • Loading branch information
earlinn committed Feb 5, 2024
1 parent 3c4bfa9 commit 06fdcac
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 126 deletions.
18 changes: 12 additions & 6 deletions backend/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
from products.models import Product


class CharFilterInFilter(rf_filters.BaseInFilter, rf_filters.CharFilter):
"""Custom char filter allowing comma-separated incoming values."""

pass


class ProductFilter(rf_filters.FilterSet):
"""Class for filtering products."""

name = rf_filters.CharFilter(method="startswith_contains_union_method")
category = rf_filters.AllValuesMultipleFilter(field_name="category__slug")
subcategory = rf_filters.AllValuesMultipleFilter(field_name="subcategory__slug")
producer = rf_filters.AllValuesMultipleFilter(field_name="producer__slug")
components = rf_filters.AllValuesMultipleFilter(field_name="components__slug")
tags = rf_filters.AllValuesMultipleFilter(field_name="tags__slug")
promotions = rf_filters.AllValuesMultipleFilter(field_name="promotions__slug")
category = CharFilterInFilter(field_name="category__slug")
subcategory = CharFilterInFilter(field_name="subcategory__slug")
producer = CharFilterInFilter(field_name="producer__slug")
components = CharFilterInFilter(field_name="components__slug")
tags = CharFilterInFilter(field_name="tags__slug")
promotions = CharFilterInFilter(field_name="promotions__slug")
is_favorited = rf_filters.NumberFilter(method="product_boolean_methods")
min_price = rf_filters.NumberFilter(method="get_min_price")
max_price = rf_filters.NumberFilter(method="get_max_price")
Expand Down
4 changes: 1 addition & 3 deletions backend/orders/shopping_carts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from django.utils import timezone

from core.loggers import logger
from products.models import Coupon, Product

PRICE_DECIMAL_PLACES = 2
from products.models import PRICE_DECIMAL_PLACES, Coupon, Product


class ShopCart(object):
Expand Down
Loading

0 comments on commit 06fdcac

Please sign in to comment.