在django admin中显示不同的名称

时间:2013-08-06 16:05:47

标签: python django

我有  在admin.py中:

class PurchaseOrderAdmin(admin.ModelAdmin):
    fields = ['product', 'dollar_amount']

在models.py

class PurchaseOrder(models.Model):
    product = models.CharField(max_length=256)
    dollar_amount = models.FloatField()

我想将'dollar_amount'显示为'价格'。我该怎么做?

2 个答案:

答案 0 :(得分:1)

将dollar_amount字段的verbose_name设置为“price。”

修改

class PurchaseOrder(models.Model):
    product = models.CharField(max_length=256)
    dollar_amount = models.FloatField(verbose_name='Price')

答案 1 :(得分:0)

in models.py:

class PurchaseOrder(models.Model):
  product = models.CharField(max_length=256)
  dollar_amount = models.FloatField()

  def price(self):
    return self.dollar_amount

in admin.py:

 class PurchaseOrderAdmin(admin.ModelAdmin):
  list_display=('product','price')