如何更改Django Admin自定义列表字段标签

时间:2010-11-10 05:22:28

标签: django-admin

如何更改in_stock verbose_name?

Models.py

class Book(models.Model):
 name = models.CharField(u"Нэр", max_length = 200)

 @property
 def in_stock(self):
  return self.stocks.count()

Im Admin.py

class BookAdmin(admin.ModelAdmin):
 list_display  = ('name', 'in_stock')
 search_fields = ('name', )

2 个答案:

答案 0 :(得分:36)

我猜你应该使用short_description属性。 Django-admin

def in_stock(self):
  return self.stocks.count()
in_stock.short_description = 'Your label here'

答案 1 :(得分:0)

将模型和verbose_name参数更改为field。我将“作者”标签更改为“作者”

models.py

class books(models.Model):
    title = models.CharField(max_length = 250)
    author= models.CharField(max_length = 250, verbose_name='Author(s)')

或者简单地

author      = models.CharField('Author(s)',max_length = 250)