在管理界面(Django)中显示带有尾随货币符号的可编辑十进制字段

时间:2017-05-14 20:30:09

标签: python django django-models django-admin

我有一个简单的模型:

class Product(models.Model):
    ...
    price = models.DecimalField(max_digits=4, decimal_places=2)
    ...

    def price_currency(self):
        return '%.2f €' % self.price

和管理员模型:

class ProductAdmin(admin.ModelAdmin):
    list_display = ['price_currency']

获得此产品列表概述(仅限价格列截图):

enter image description here

问题是该字段不可编辑(在列表视图中)。有没有办法让它可以编辑并在结尾显示尾随货币符号?

我可以致电list_display = ['price']list_editable = ['price'],问题是它最后没有显示欧元符号,即:

enter image description here

我理想的最终目标是:

enter image description here

0 个答案:

没有答案