Django中list_editable的千位分隔符? [英] Thousand separator for list_editable in django?

查看:175
本文介绍了Django中list_editable的千位分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*在django中,list_editable是否有一千个分隔符(例如1,000)?

*Is there a thousand separator (like 1,000) for list_editable in django?

#model.py
class Product(models.Model):
deal_price = models.IntegerField(db_index=True, blank=True, null=True, default=0, validators=[position], verbose_name=_("Current Price"))

-//-

class StockProduct(Product):
    category = models.ForeignKey(to=StockCategory, related_name='stock_products')
    warehouse = models.ForeignKey(to=WareHouse, blank=True, null=True)

    objects = ProductManager()

#admin.py
class StockProductAdmin(admin.ModelAdmin):
    form = StockProductAdminForm
    list_display = ('product_id', 'title', 'quantity', 'category', 'deal_price_sep')
    list_editable = ('quantity', 'deal_price_sep')

def deal_price_sep(self, instance):
        return '{0:,}'.format(self.deal_price)

admin.site.register(models.StockProduct, StockProductAdmin)

每当我将deal_price_sep更改为deal_price时,它就会起作用。但是我想要带千位分隔符的list_editable显示价格。

Whenever I change deal_price_sep to deal_price, it works. But I want the list_editable show price with thousand separator.

推荐答案

如果有人还想显示更大的数字:

In case anybody also wants to display more big numbers:

添加到设置文件中的默认设置(例如settings.py):

Add to the default settings in the your settings file (e.g. settings.py):

USE_THOUSAND_SEPARATOR = True

来源

这篇关于Django中list_editable的千位分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆