Using Django's built-in admin site in Django

 Using Django's built-in admin site in Django


Django provides a built-in admin site that we can use to manage our application's data. We can customize the admin site by registering our models and defining custom admin classes. Here's an example admin class for the Post model:


python


from django.contrib import admin

from .models import Post


class PostAdmin(admin.ModelAdmin):

    list_display = ('title', 'created_at')


admin.site.register(Post, PostAdmin)


In this example, we define a PostAdmin class that inherits from Django's ModelAdmin class. We set the list_display attribute to specify the fields that we want to display in the list view of the admin site. We register the Post model with the admin site and associate it with the PostAdmin class.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...