【发布时间】:2022-01-16 02:07:05
【问题描述】:
这是我的模型:
from django.contrib.humanize.templatetags.humanize import intcomma
class Flow(models.Model):
amount = models.DecimalField(max_digits=10, decimal_places=2)
def df_amount(self):
return '{intcomma(abs(self.amount)):>12}'
df_amount.admin_order_field = 'amount'
df_amount.short_description = 'amount'
在admin.py,
@admin.register(Flow)
class FlowAdmin(admin.ModelAdmin):
list_display = (
'df_amount',
)
对于amount=2800,print(self.df_amount()) 给出$ 2,800.00
但$ 2,800.00 显示在管理面板中,中间的空格被截断为一个空格,与预期不符。
所以我的问题是如何在管理面板中保留字符串中间的空格?谢谢!
【问题讨论】:
标签: django django-admin