Junior — Middle
How can the display of model data be configured or modified in the admin panel?
sobes.tech AI
Answer from AI
In Django admin panel, data display for a model is configured through the ModelAdmin class.
To change the display, create a class inheriting from admin.ModelAdmin and register the model with this class. Main configuration parameters include:
list_display— fields shown in the list view.list_filter— filters for sidebar.search_fields— fields to search.ordering— sort order.
Example:
from django.contrib import admin
from .models import Product
class ProductAdmin(admin.ModelAdmin):
list_display = ('name', 'price', 'available')
list_filter = ('available', 'category')
search_fields = ('name',)
ordering = ('name',)
admin.site.register(Product, ProductAdmin)
This allows flexible customization of how fields are displayed in the admin interface.