Answer the question
In order to leave comments, you need to log in
How to change the display title of a column in the django admin?
I have a model:
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 = 'Клиенты'
@admin.register(Customers)
class UserAccessAdmin(admin.ModelAdmin):
list_display = ('fio_min', 'all_sum', 'all_sum_already', 'all_debt')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question