Customizing Model Properties & Classes in Django’s Admin

Django's admin list display view

Verbose names in Django allow you to customize the headings in list_display, form fields, and even the name that appears in the admin for the model Class. Adding a verbose name to any model, property, or method will ensure that pretty names are used everywhere in the Django admin. In the example below, the model Class Ppl would appear in the admin as Person, fName would appear as First Name, and anytime you get the full name in the list display for Person that table header would be Full Name rather than Get full name.

class Ppl(models.Model):
    # Verbose name for CharField
    fName = models.CharField('First Name', max_length=100)
    lName = models.CharField('Last Name', max_length=100)
    pAge = models.IntegerField(null=True, blank=True)

    def get_full_name(self):
        return fName + lName
    # Verbose name for method
    get_full_name.short_description = 'Full Name' 

    class Meta:
        # Verbose name for model Class
        verbose_name = 'Person'
        # Orders the people by first name then last name in admin
        ordering = ['fName', 'lName']

Note: I suggest that you name model Classes singular because Django will make them plural by adding an ‘s’ in certain views.

About the author

I like learning, programming, and creating. I'm an incessant problem solver, and have an insatiable desire to absorb information. I'm an information sponge. A critical thinker. My left brain and right brain function as one. Business and technology should be one. I invest based on opportunity or technicals, whichever is right. I never let my schooling interfere with my education. Marketing is not fluff, it is data-driven. I find patterns, and analyze the random. I like to teach and explain.

Leave a Reply