I have two models (Country and State) and I've made only one ModelAdmin for Country with an TabularInline for State.
class StateInline(admin.TabularInline):
model = State
class CountryAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['name']}),
]
inlines = [StateInline]
admin.site.register(Country, CountryAdmin)
How can I override the verbose_name
Meta property of Country model? I want to rename the form in menu to "Countries / States", instead of only "Countries"?
verbose_name is a human-readable name for the field. If the verbose name isn't given, Django will automatically create it using the field's attribute name, converting underscores to spaces. This attribute in general changes the field name in admin interface.
To automate this process, we can programmatically fetch all the models in the project and register them with the admin interface. Open admin.py file and add this code to it. This will fetch all the models in all apps and registers them with the admin interface.
from django. contrib import admin # Register your models here. Register the models by copying the following text into the bottom of the file. This code imports the models and then calls admin.
It provides a simple UI for creating, editing and deleting data defined with the Django ORM. In this article we are going to enable the admin user interface for a simple model and customize it from a simple list view to a more user friendly table like interface.
using Meta
in your model:
from django.utils.tranlation import gettext_lazy as _
class Country(models.Model):
# your fields
class Meta:
verbose_name = _("Country / State")
verbose_name_plural = _("Countries / States")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With