71
I guess you should use short_description attribute. Django-admin
def my_stock(self):
return self.stock
my_stock.short_description = 'Your label here'
5
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)
- [Django]-How to backup a django db
- [Django]-No module named 'polls.apps.PollsConfigdjango'; Django project tutorial 2
- [Django]-Which Python API should be used with Mongo DB and Django
2
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
- [Django]-For what purpose Django is used for?
- [Django]-"Failed building wheel for psycopg2" – MacOSX using virtualenv and pip
- [Django]-Using Django Rest Framework, how can I upload a file AND send a JSON payload?
Source:stackexchange.com