Can you change a field label in the Django Admin application?

PythonPython 3.xDjangoDjango FormsDjango Admin

Python Problem Overview


As the title suggests. I want to be able to change the label of a single field in the admin application. I'm aware of the Form.field attribute, but how do I get my Model or ModelAdmin to pass along that information?

Python Solutions


Solution 1 - Python

the verbose name of the field is the (optional) first parameter at field construction.

Solution 2 - Python

If your field is a property (a method) then you should use short_description:

class Person(models.Model):
    ...
    
    def address_report(self, instance):
        ...
    # short_description functions like a model field's verbose_name
    address_report.short_description = "Address"

Solution 3 - Python

As Javier suggested you can use verbose name in your fields in model.py. Example as below,

class Employee(models.Model):
     name = models.CharField(max_length = 100)
     dob = models.DateField('Date Of Birth')
     doj = models.DateField(verbose_name='Date Of Joining')
     mobile=models.IntegerField(max_length = 12)
     email = models.EmailField(max_length=50)
     bill = models.BooleanField(db_index=True,default=False)
     proj = models.ForeignKey(Project, verbose_name='Project')

Here the dob,doj and proj files will display its name in admin form as per the verbose_name mentioned to those fields.

Solution 4 - Python

from django.db import models

class MyClassName(models.Model):    
    field_name = models.IntegerField(verbose_name='Field Caption')

Solution 5 - Python

Building on Javier's answer; if you need one label in forms (on the front-end) and another label on admin it is best to set internal (admin) one in the model and overwrite it on forms. Admin will of course use the label in the model field automatically.

Solution 6 - Python

Use "verbose_name" to change a field name as the example below.

"models.py":

from django.db import models

class MyModel(models.Model):              # Here
  name = models.CharField(max_length=255, verbose_name="My Name")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJosh SmeatonView Question on Stackoverflow
Solution 1 - PythonJavierView Answer on Stackoverflow
Solution 2 - PythonSepermanView Answer on Stackoverflow
Solution 3 - PythonNaggappan RamukannanView Answer on Stackoverflow
Solution 4 - PythonMajid ZandiView Answer on Stackoverflow
Solution 5 - PythonmuhukView Answer on Stackoverflow
Solution 6 - PythonKai - Kazuya ItoView Answer on Stackoverflow