Thousand separator for list_editable in django?

前端 未结 2 759
死守一世寂寞
死守一世寂寞 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 04:59

    In case anybody also wants to display more big numbers:

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

    USE_THOUSAND_SEPARATOR = True
    

    Source

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题