Issue
My admin.py file
from django.contrib import admin
from . models import contactEnquiries
class ContactAdmin(admin.ModelAdmin):
list_display = ['cn_name', 'cn_email', 'cn_number']
@admin.display(description='Name')
def cn_name(self, obj):
return obj
admin.site.register(contactEnquiries, ContactAdmin)
I want to display the column titles as - Name, Email, Number instead of 'cn_name', 'cn_email', 'cn_number'
in the admin panel. I tried the above code but I am not sure how to do it? Can anyone please help?
Solution
You can use verbose_name
in your model itself without affecting your database or any other function. Like this column_name = models.CharField(verbose_name="name you desire")
and that will change the name of your column in django admin for you.
In your case you use the following code:
class contactEnquiries(model.Models):
cn_name = models.CharField(verbose_name="Name", your other config)
#your all other columns here and you can user verbose_name in all your model columns.
You can read the documentation here: https://docs.djangoproject.com/en/4.1/ref/models/options/#verbose-name
Answered By - Divya Prakash
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.