image
Introduction to Django (Part 4)
#Python #Programming #Beginner #Django

Hey, here we are with the part 4 of the series introduction to Django. If you haven't gone through the previous blogs please do so before you continue with this...
In this article we will continue from where we left, and that's registering our models to our admin panel so that we can CRUD functionalities from our admin dashboard.
Hope you have your models.py file ready as we did in our previous article, now we have to go to our admin.py file and add the following code;

from django.contrib import admin
from .models import BlogPost

class PostAdmin(admin.ModelAdmin):
    list_display = ('title', 'slug', 'status',
                    'created_on', 'blog_views')
    list_filter = ("status",)
    search_fields = ['title', 'content']
    prepopulated_fields = {'slug': ('title',)}

admin.site.register(BlogPost, PostAdmin)


In the above example we have now registered the model we created to our admin dashboard. 
The PostAdmin class is not that important, though it helps us in locating what blogs we have in our database easily. 
That's all we had to to register our models. You can have as many tables as you like, though how you'll register them in your admin.py file will be slightly different from what we have done above. 
That's all for this article. Next we will get into creating our templates. 
Hope you've learned something today, don't forget to hit that upvote button if this article helped.
See you soon