How can arrange the model index page columns in Django admin?

To arrange the model index page columns in Django admin, you can define the list_display attribute in the corresponding ModelAdmin class.

Here's an example of how you can arrange the columns:


from django.contrib import admin
from .models import YourModel

class YourModelAdmin(admin.ModelAdmin):
    list_display = ('field1', 'field2', 'field3')  # Specify the fields to be displayed as columns

admin.site.register(YourModel, YourModelAdmin)

In the above example, replace 'field1', 'field2', and 'field3' with the actual fields from your model that you want to display as columns on the model index page. You can add more fields to the list_display tuple if needed.

Make sure to import your model (YourModel) and register it with the custom ModelAdmin (YourModelAdmin) in the Django admin site using admin.site.register(YourModel, YourModelAdmin). This will ensure that the custom configuration is applied to the model in the admin interface.

Once you've made these changes, the model index page in the Django admin should display the specified fields as columns in the specified order.

Comments

Leave a Reply