Django has a build in panel which has a lot of functionality that comes to use of the user.To add these functionality it is quite very easy at first when you open up the panel you wont have any functionality to add them let me show you how to add them.And Please remember that this is for those people who know the basics of Django
1 Go To Models
First you have to go to your models.py and you have to create models.
from django.db import models
class Student(models.Model): name = models.CharField(max_length=250) invoice = models.CharField(max_length=250) address = models.CharField(max_length=250) rollno = models.CharField(max_length=250) updated = models.DateTimeField(auto_now=True, auto_now_add=False) timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
Now once you have done this write these commands in the terminalclass Meta: ordering = ["-timestamp", "-updated"]
Also Dont forget to register your app in settings.py
2 Go To Admin
Once opened admin.py then type this
from django.contrib import admin from .models import Student class StudentModelAdmin(admin.ModelAdmin): list_display = ["name", "updated", "timestamp"] list_display_links = ["updated"] list_editable = ["name"] list_filter = ["updated", "timestamp"] search_fields = ["name", "rollno"] class Meta: model = Student admin.site.register(Student,StudentModelAdmin)Now once you have written all of this now we can start you server and go to your admin panel
Click on Student then this will pop up
3 Demo
Now you can easily edit any student you can also see the date when they were added , the day when they were updated , search any student and on the right side there is a filter which you can easily use it . Please note that there may be somethings i may miss but if you run into errors please let me know and i will help you.
Comments
Post a Comment