2019年11月23日土曜日

Django Admin画面でフィールドの名前を変える方法

How to change Django Admin Custom list field label - Stack Overflow
https://stackoverflow.com/questions/4141471/how-to-change-django-admin-custom-list-field-label

How to change 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()

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



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

0 件のコメント:

コメントを投稿