Reputation: 1138
How to change my_stock
verbose_name?
models.py:
class Book(models.Model):
name = models.CharField(u"Нэр", max_length=200)
stock = models.IntegerField()
@property
def my_stock(self):
return self.stock
admin.py:
class BookAdmin(admin.ModelAdmin):
list_display = ('name', 'my_stock')
search_fields = ('name', )
Upvotes: 50
Views: 27040
Reputation: 1
You can create the custom column "my_stock" with my_stock()
then can rename it with @admin.display as shown below:
# "models.py"
class Book(models.Model):
name = models.CharField(u"Нэр", max_length=200)
stock = models.IntegerField()
# @property
# def in_stock(self):
# return self.stocks.count()
# "admin.py"
class BookAdmin(admin.ModelAdmin):
list_display = ('name', 'my_stock')
search_fields = ('name', )
# ↓ Displayed
@admin.display(description='Your label here')
def my_stock(self, obj):
return obj.stock
Upvotes: 4
Reputation: 5184
I guess you should use short_description attribute. Django-admin
def my_stock(self):
return self.stock
my_stock.short_description = 'Your label here'
Upvotes: 73
Reputation: 2037
change your model and verbose_name parametr to field. I change "author" label to "Author(s)"
models.py
class books(models.Model):
title = models.CharField(max_length = 250)
author= models.CharField(max_length = 250, verbose_name='Author(s)')
or simply
author = models.CharField('Author(s)',max_length = 250)
Upvotes: 5