feat: add favorites feature for users
All checks were successful
Build and Push Docker Image / build (push) Successful in 51s
All checks were successful
Build and Push Docker Image / build (push) Successful in 51s
- Implemented `Favorite` model with unique user-item constraint and timestamped records - Added `favorites:index` and `favorites:toggle` views with AJAX support for toggling favorites - Built templates and front-end assets for the favorites page and integration with item grids - Extended header with favorites link and dynamic counter - Added tests covering models, views, and templates for the favorites functionality - Updated admin to enable management of favorites via Django admin interface
This commit is contained in:
@@ -1,2 +1,46 @@
|
||||
from django.db.models import Prefetch
|
||||
|
||||
from items.models import Category, Subcategory
|
||||
|
||||
|
||||
def navigation(request):
|
||||
return {"active": ""}
|
||||
categories = (
|
||||
Category.objects
|
||||
.prefetch_related(Prefetch("subcategories", queryset=Subcategory.objects.order_by("name")))
|
||||
.order_by("name")
|
||||
)
|
||||
|
||||
current_category = None
|
||||
current_subcategory = None
|
||||
selected_label = "Все категории"
|
||||
selected_value = ""
|
||||
resolver_match = getattr(request, "resolver_match", None)
|
||||
category_slug = None
|
||||
if resolver_match is not None:
|
||||
category_slug = resolver_match.kwargs.get("category")
|
||||
|
||||
if category_slug:
|
||||
current_category = Category.objects.filter(slug=category_slug.lower()).first()
|
||||
|
||||
subcategory_slug = request.GET.get("subcategory")
|
||||
if current_category and subcategory_slug:
|
||||
current_subcategory = Subcategory.objects.filter(
|
||||
category=current_category,
|
||||
slug=subcategory_slug.lower(),
|
||||
).first()
|
||||
|
||||
if current_category and current_subcategory:
|
||||
selected_label = f"{current_category.name} / {current_subcategory.name}"
|
||||
selected_value = f"subcategory:{current_category.slug}:{current_subcategory.slug}"
|
||||
elif current_category:
|
||||
selected_label = current_category.name
|
||||
selected_value = f"category:{current_category.slug}"
|
||||
|
||||
return {
|
||||
"active": "",
|
||||
"navigation_categories": categories,
|
||||
"navigation_selected_label": selected_label,
|
||||
"navigation_selected_value": selected_value,
|
||||
"navigation_selected_category_slug": current_category.slug if current_category else None,
|
||||
"navigation_selected_subcategory_slug": current_subcategory.slug if current_subcategory else None,
|
||||
}
|
||||
|
||||
@@ -188,6 +188,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.staticfiles',
|
||||
'home',
|
||||
'items',
|
||||
'favorites',
|
||||
'orders',
|
||||
'users',
|
||||
]
|
||||
@@ -368,6 +369,11 @@ LOGGING = {
|
||||
"level": LOG_LEVEL,
|
||||
"propagate": False,
|
||||
},
|
||||
"favorites": {
|
||||
"handlers": ["console"],
|
||||
"level": LOG_LEVEL,
|
||||
"propagate": False,
|
||||
},
|
||||
"orders": {
|
||||
"handlers": ["console"],
|
||||
"level": LOG_LEVEL,
|
||||
|
||||
@@ -28,6 +28,7 @@ urlpatterns = [
|
||||
path("favicon.ico", views.favicon, name="favicon"),
|
||||
path('', include('home.urls')),
|
||||
path('catalog/', include('items.urls')),
|
||||
path('favorites/', include('favorites.urls')),
|
||||
path('orders/', include('orders.urls')),
|
||||
path('users/', include('users.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
|
||||
Reference in New Issue
Block a user