* django中的list_editable是否有一千个分隔符(如1,000)?
#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显示价格为千分隔符。
答案 0 :(得分:0)
我还没有测试过这个,但我认为你应该可以做到:
class PersonAdmin(admin.ModelAdmin):
list_editable = ('foo_thousand',)
list_display = ('foo_thousand',)
def foo_thousand(self, instance):
return '{0:,}'.format(self.foo)
但是,在保存之前,您可能需要删除不是数字的字符。您可以使用save_model()
方法执行此操作。
答案 1 :(得分:0)