2013-08-06 122 views
0

一个不同的名字,我有 在admin.py:显示在Django管理

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' 作为 '价格'。我会怎么做?

回答

1

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

编辑:

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

哪里放呢?我在admin.py中试过,但是它给出了一个错误。 – Mdjon26

+0

看我的编辑。你把它放在你的models.py中。 – garnertb

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')