filmov
tv
Django Tutorial: Adding Our Model To The Django Admin Site
Показать описание
In this Django tutorial, we are going to learn how to add a model to the Django administration site. This process is pretty simple. The way the Django framework is designed allows for us to add our models to the Django administration site in just a few lines of code.
Add A Model To The Django Administration Site
# Register your models here.
The admin package has a ton of features which we can not cover in one tutorial so we will cover a few here and follow up later to cover more admin features.
Import Our Model
# Register your models here.
from .models import Lesson
If we ran the server now and looked at our admin site we would not see anything change. We need to still register the class(database table) for the admin interface to interact with the database.
Register Class
# Register your models here.
from .models import Lesson
Now open up your site and go to the admin section. You will see a new section called Lessons.
add model to admin site django
Now if you click on add you can add a lesson. If you click on change you can change a lesson and if you click on lessons you can see all the lessons. Pretty cool.
Conclusion
In this Django tutorial, we took a look at how to to add a model to the Django administration site. If you have any questions leave a comment below. In the next tutorial we will look at different ways to improve the admin interface for this app.
Комментарии