feat: 现代化翻页组件 + 完整项目更新
- 新增 Pagination 通用组件:首页/上一页/页码/下一页/末页导航 - PickModal 和 SwapModal 集成分页功能,每页20项 - 搜索/筛选切换自动回到第1页 - 现代化CSS样式:hover浮起动效、主色高亮、移动端适配 - 新增 dashboard、admin 管理模板 - 菜系(cuisine)模型和迁移 - 构建脚本 build.py 支持 PyInstaller 打包 - 前端资源重新构建
This commit is contained in:
+35
-4
@@ -1,7 +1,32 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html, mark_safe
|
||||
|
||||
from .models import Dish
|
||||
from .models import Cuisine, Dish
|
||||
|
||||
|
||||
@admin.action(description='启用所选菜系')
|
||||
def activate_cuisines(modeladmin, request, queryset):
|
||||
queryset.update(is_active=True)
|
||||
|
||||
|
||||
@admin.action(description='停用所选菜系')
|
||||
def deactivate_cuisines(modeladmin, request, queryset):
|
||||
queryset.update(is_active=False)
|
||||
|
||||
|
||||
@admin.register(Cuisine)
|
||||
class CuisineAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'description', 'sort_order', 'is_active', 'dish_count_display', 'created_at')
|
||||
list_editable = ('sort_order', 'is_active')
|
||||
list_filter = ('is_active',)
|
||||
search_fields = ('name',)
|
||||
list_per_page = 50
|
||||
actions = [activate_cuisines, deactivate_cuisines]
|
||||
|
||||
@admin.display(description='菜品数')
|
||||
def dish_count_display(self, obj):
|
||||
count = obj.dishes.count()
|
||||
return format_html('<span style="font-weight:600">{}</span>', count)
|
||||
|
||||
|
||||
@admin.action(description='启用所选菜品(参与自动生成)')
|
||||
@@ -16,10 +41,10 @@ def deactivate_dishes(modeladmin, request, queryset):
|
||||
|
||||
@admin.register(Dish)
|
||||
class DishAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'cuisine', 'dish_type_display', 'ingredient_detail', 'protein', 'fat', 'calorie', 'nutri_badge', 'is_active', 'created_at')
|
||||
list_display = ('name', 'cuisine_display', 'dish_type_display', 'ingredient_detail', 'protein', 'fat', 'calorie', 'nutri_badge', 'is_active', 'created_at')
|
||||
list_filter = ('dish_type', 'cuisine', 'is_active')
|
||||
search_fields = ('name', 'ingredient_detail', 'cuisine', 'pinyin')
|
||||
list_editable = ('cuisine', 'ingredient_detail', 'protein', 'fat', 'calorie', 'is_active')
|
||||
search_fields = ('name', 'ingredient_detail', 'cuisine__name', 'pinyin')
|
||||
list_editable = ('ingredient_detail', 'protein', 'fat', 'calorie', 'is_active')
|
||||
list_per_page = 50
|
||||
actions = [activate_dishes, deactivate_dishes]
|
||||
fieldsets = (
|
||||
@@ -28,6 +53,12 @@ class DishAdmin(admin.ModelAdmin):
|
||||
('其他', {'fields': ('description',), 'classes': ('collapse',)}),
|
||||
)
|
||||
|
||||
@admin.display(description='菜系', ordering='cuisine')
|
||||
def cuisine_display(self, obj):
|
||||
if obj.cuisine:
|
||||
return obj.cuisine.name
|
||||
return '—'
|
||||
|
||||
@admin.display(description='营养提示', ordering='calorie')
|
||||
def nutri_badge(self, obj):
|
||||
badges = []
|
||||
|
||||
Reference in New Issue
Block a user