django admin site change the display label of field

Question:

I hope the title is enough to understand what my issue is, I just want to change the default label Fathers Lastname: into Lastname without changing the table field name in the models

enter image description here

This is my models.py:

class ParentsProfile(models.Model):
    Fathers_Firstname = models.CharField(max_length=500,null=True,blank=True)
    Fathers_Middle_Initial = models.CharField("Middle Initial",max_length=500,null=True,blank=True, help_text="Father")
    Fathers_Lastname = models.CharField(max_length=500,null=True,blank=True)
Asked By: user12966778

||

Answers:

Yes, you can change the label name by adding the first postional attribute to the field.

use the code below:

Fathers_Firstname = models.CharField("Lastname",max_length=500,null=True,blank=True)
Answered By: Anar Rzayev

try adding verbose_name

Fathers_Firstname = models.CharField(verbose_name="Lastname",max_length=500,null=True,blank=True)
Answered By: Ajay Kumar

You can create the custom column "lastname" with lastname() and can rename it with @admin.display as shown below:

# "admin.py"

from django.contrib import admin
from .models import ParentsProfile

@admin.register(ParentsProfile)
class ParentsProfileAdmin(admin.ModelAdmin):
    list_display = ('lastname',) # ← "lastname()" needs to be assigned  
                                 # ↓ Displayed  
    @admin.display(description='Lastname')
    def lastname(self, obj):
        return obj.Fathers_Firstname
Answered By: Kai – Kazuya Ito