- 新增 Pagination 通用组件:首页/上一页/页码/下一页/末页导航 - PickModal 和 SwapModal 集成分页功能,每页20项 - 搜索/筛选切换自动回到第1页 - 现代化CSS样式:hover浮起动效、主色高亮、移动端适配 - 新增 dashboard、admin 管理模板 - 菜系(cuisine)模型和迁移 - 构建脚本 build.py 支持 PyInstaller 打包 - 前端资源重新构建
68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
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', '荤菜'),
|
|
('veg', '素菜'),
|
|
('soup', '汤'),
|
|
('staple', '主食'),
|
|
]
|
|
|
|
name = models.CharField('菜名', max_length=100, unique=True)
|
|
dish_type = models.CharField('类型', max_length=10, choices=TYPE_CHOICES)
|
|
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)
|
|
calorie = models.IntegerField('热量(kcal)', default=0)
|
|
description = models.CharField('备注', max_length=200, blank=True)
|
|
is_active = models.BooleanField('启用', default=True)
|
|
pinyin = models.CharField('拼音索引', max_length=200, blank=True, editable=False)
|
|
created_at = models.DateTimeField('创建时间', auto_now_add=True)
|
|
|
|
class Meta:
|
|
ordering = ['dish_type', 'id']
|
|
verbose_name = '菜品'
|
|
verbose_name_plural = '菜品'
|
|
|
|
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))
|
|
initials = ''.join(lazy_pinyin(self.name, style=Style.FIRST_LETTER))
|
|
self.pinyin = f'{full} {initials}'
|
|
super().save(*args, **kwargs)
|