Thousand separator for list_editable in django?

前端 未结 2 760
死守一世寂寞
死守一世寂寞 2021-01-26 04:57

*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, b         


        
2条回答
  •  抹茶落季
    2021-01-26 05:19

    I haven't tested this, but I think you should be able to do:

    class PersonAdmin(admin.ModelAdmin):
        list_editable = ('foo_thousand',)
        list_display = ('foo_thousand',)
    
        def foo_thousand(self, instance):
            return '{0:,}'.format(self.foo)
    

    But then you will probably need to strip out the chars that are not digits before you save. You could do that in the save_model() method.

提交回复
热议问题