feat: 现代化翻页组件 + 完整项目更新
- 新增 Pagination 通用组件:首页/上一页/页码/下一页/末页导航 - PickModal 和 SwapModal 集成分页功能,每页20项 - 搜索/筛选切换自动回到第1页 - 现代化CSS样式:hover浮起动效、主色高亮、移动端适配 - 新增 dashboard、admin 管理模板 - 菜系(cuisine)模型和迁移 - 构建脚本 build.py 支持 PyInstaller 打包 - 前端资源重新构建
This commit is contained in:
+29
-12
@@ -3,6 +3,23 @@ from django.db import models
|
||||
from pypinyin import Style, lazy_pinyin
|
||||
|
||||
|
||||
class Cuisine(models.Model):
|
||||
"""菜系:可动态管理的菜系分类"""
|
||||
name = models.CharField('菜系名称', max_length=50, unique=True)
|
||||
description = models.CharField('描述', max_length=200, blank=True, default='')
|
||||
sort_order = models.IntegerField('排序', default=0, help_text='数值越小越靠前')
|
||||
is_active = models.BooleanField('启用', default=True)
|
||||
created_at = models.DateTimeField('创建时间', auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['sort_order', 'id']
|
||||
verbose_name = '菜系'
|
||||
verbose_name_plural = '菜系'
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Dish(models.Model):
|
||||
TYPE_CHOICES = [
|
||||
('meat', '荤菜'),
|
||||
@@ -10,21 +27,17 @@ class Dish(models.Model):
|
||||
('soup', '汤'),
|
||||
('staple', '主食'),
|
||||
]
|
||||
CUISINE_CHOICES = [
|
||||
('家常菜', '家常菜'),
|
||||
('本帮菜', '本帮菜'),
|
||||
('江浙菜', '江浙菜'),
|
||||
('川菜', '川菜'),
|
||||
('粤菜', '粤菜'),
|
||||
('鲁菜', '鲁菜'),
|
||||
('湘菜', '湘菜'),
|
||||
('西北菜', '西北菜'),
|
||||
('面点小吃', '面点小吃'),
|
||||
]
|
||||
|
||||
name = models.CharField('菜名', max_length=100, unique=True)
|
||||
dish_type = models.CharField('类型', max_length=10, choices=TYPE_CHOICES)
|
||||
cuisine = models.CharField('菜系', max_length=20, choices=CUISINE_CHOICES, blank=True, default='家常菜')
|
||||
cuisine = models.ForeignKey(
|
||||
Cuisine,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name='dishes',
|
||||
verbose_name='菜系',
|
||||
)
|
||||
ingredient_detail = models.CharField('配料明细', max_length=200, blank=True, help_text='例如:牛心菜85g五花肉片15g')
|
||||
protein = models.DecimalField('蛋白质(g)', max_digits=6, decimal_places=1, default=0)
|
||||
fat = models.DecimalField('脂肪(g)', max_digits=6, decimal_places=1, default=0)
|
||||
@@ -42,6 +55,10 @@ class Dish(models.Model):
|
||||
def __str__(self):
|
||||
return f'{self.get_dish_type_display()}: {self.name}'
|
||||
|
||||
@property
|
||||
def cuisine_name(self):
|
||||
return self.cuisine.name if self.cuisine else ''
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.name:
|
||||
full = ''.join(lazy_pinyin(self.name))
|
||||
|
||||
Reference in New Issue
Block a user