修改djangoadmin字段中⽂名的两种⽅式使⽤django admin 显⽰字段⾃定义def的时候默认会显⽰成函数名称,使⽤⼀下⽅法可⾃定义显⽰名称第⼀种
class TemplateRequestLog(models.Model):
templateApp = models.ForeignKey(TemplateApp, verbose_name="模板名称", on_delete=models.CASCADE)
django admin 自定义页面
requestUrl = models.URLField(verbose_name="请求路径")
createTime = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
lastTime = models.DateTimeField(auto_now=True, verbose_name="修改时间")
editor = models.ForeignKey(User, null=True, on_delete=models.CASCADE, verbose_name="修改者")
class Meta:
verbose_name_plural = "访问记录"
def requestName(self):
return self.editor.first_name
requestName.short_description = "昵称"  # 直接修改
第⼆种
def rename(newname):
def decorator(fn):
fn.__name__ = newname
return fn
return decorator
class AppNews(models.Model):
topImage = models.ImageField(upload_to='../static/uploadImage/AppNews/%Y/%m/%d', verbose_name='滚动图⽚', null=True,
blank=True)
createTime = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
lastTime = models.DateTimeField(auto_now=True, verbose_name="修改时间")
editor = models.ForeignKey(User, null=True, on_delete=models.CASCADE, verbose_name="修改者")
class Meta:
verbose_name_plural = "滚动新闻"
@rename("模板头像")  # 添加在顶部
def showTopImage(self):
return format_html("<img src='/{}' class='showAvatar'/>", pImage)
def__str__(self):
return self.describe

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。