您可以改用属性,例如:
from django.contrib import admin
class Example(Basemodel):
price = models.IntegerField(default=0)
@property
@admin.display(description='price', ordering='price')
def price_formatted(self):
return f'{self.price:,}'
并使用该属性:
@admin.register(Example)
class ExampleAdmin(admin.ModelAdmin):
list_display = ('price_formatted',)