D
D
Daniil Chernov2020-08-27 15:58:49
Django
Daniil Chernov, 2020-08-27 15:58:49

How to change the display title of a column in the django admin?

I have a model:

spoiler
class Customers(models.Model):
    URFACE = 'UR'
    FIZFACE = 'FI'
    FACE = (
        (URFACE, 'Юридическое лицо'),
        (FIZFACE, 'Физическое лицо'),
    )
    type = models.CharField(max_length=2, choices=FACE, default=FIZFACE)
    name = models.CharField(max_length=200, verbose_name='Имя')
    surname = models.CharField(max_length=200, verbose_name='Фамилия')
    patronymic = models.CharField(max_length=200, verbose_name='Отчество')
    dr = models.DateField(verbose_name='День рождения')
    pasno = models.CharField(max_length=200, verbose_name='Серия и номер паспорта')
    pasby = models.CharField(max_length=200, verbose_name='Кем выдан')
    pasdate = models.DateField(verbose_name='Дата выдачи паспорта')
    paskod = models.CharField(max_length=200, verbose_name='Код подразделения паспорта')
    address = models.CharField(max_length=200, verbose_name='Прописан')
    tel = models.CharField(max_length=200, verbose_name='Телефон')
    whereknow = models.ForeignKey(WhereInfo, on_delete=models.SET_NULL, null=True, verbose_name='Источник информации')

    # Фамилия И.О.
    def fio_min(self):
        return self.surname + ' ' + self.name[0] + '. ' + self.patronymic[0] + '.'


    # Дел на сумму
    def all_sum(self):
        from affairs.models import Affairs
        all_affairs = Affairs.objects.filter(customers=self.id)
        if all_affairs.exists():
            return all_affairs.aggregate(Sum('prise'))['sum__prise']
        else:
            return 0

    # Всего оплачено
    def all_sum_already(self):
        from affairs.models import Affairs
        all_affairs = Affairs.objects.filter(customers=self.id)
        if all_affairs.exists():
            return all_affairs.aggregate(Sum('prisealready'))['sum__prisealready']
        else:
            return 0

    # Общий долг
    def all_debt(self):
        from affairs.models import Affairs
        all_affairs = Affairs.objects.filter(customers=self.id)
        if all_affairs.exists():
            return all_affairs.aggregate(Sum('customers_debt'))['sum__customers_debt']
        else:
            return 0

    # ФИО
    def __str__(self):
        return self.surname + ' ' + self.name + ' ' + self.patronymic

    class Meta:
        verbose_name = 'Клиент'
        verbose_name_plural = 'Клиенты'

I register it in the admin panel and I want to display only what is in its methods, for example, Abbreviated full name, transaction amount, paid amount and debt amount.
I register like this:
spoiler
@admin.register(Customers)
class UserAccessAdmin(admin.ModelAdmin):
    list_display = ('fio_min', 'all_sum', 'all_sum_already', 'all_debt')

Everything is displayed but I do not understand? how to change the names of the columns in the panel to your own, and not as the name of the method. On the screen circled what I want to change:
spoiler
5f47ada252c6e438453378.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-08-27
@dancha

If I'm not mistaken, short_description is for this

D
Dr. Bacon, 2020-08-27
@bacon

https://docs.djangoproject.com/en/3.1/ref/contrib/... in the examples there is how to set the name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question