A menu management application built with Django, featuring: - Dish management with cover images - Order system with party dates and participants - REST API with Django REST Framework - Bootstrap-styled frontend Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
26 lines
712 B
Python
26 lines
712 B
Python
from django.db.models import F
|
|
from menu.models import Dish
|
|
|
|
|
|
class DishService:
|
|
"""菜品业务逻辑"""
|
|
|
|
@staticmethod
|
|
def get_queryset(category_id=None, search=None):
|
|
"""获取菜品查询集"""
|
|
queryset = Dish.objects.select_related('category')
|
|
|
|
if category_id:
|
|
queryset = queryset.filter(category_id=category_id)
|
|
if search:
|
|
queryset = queryset.filter(name__icontains=search)
|
|
|
|
return queryset
|
|
|
|
@staticmethod
|
|
def increment_view_count(dish):
|
|
"""增加浏览次数"""
|
|
Dish.objects.filter(pk=dish.pk).update(view_count=F('view_count') + 1)
|
|
dish.refresh_from_db(fields=['view_count'])
|
|
return dish
|