营养校准、后台美化、静态走对象存储 CDN、标题可编辑、admin 拼音搜索
- 菜品营养按食物成分表+烹饪方式校准(calibrate_nutrition 命令) - 后台接入 jazzmin 主题美化,移除 Google Fonts(模板覆盖) - 前端/后台静态资源指向 qnycdn 对象存储 CDN(vite base + DJANGO_STATIC_URL) - 菜单标题学校名称/周数可编辑,日期随周数计算 - admin 搜索支持拼音首字母/全拼(Dish.pinyin 索引,pypinyin) - Dockerfile 使用清华 pip 镜像源
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from django.db import models
|
||||
|
||||
from pypinyin import Style, lazy_pinyin
|
||||
|
||||
|
||||
class Dish(models.Model):
|
||||
TYPE_CHOICES = [
|
||||
@@ -29,6 +31,7 @@ class Dish(models.Model):
|
||||
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:
|
||||
@@ -38,3 +41,10 @@ class Dish(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.get_dish_type_display()}: {self.name}'
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user