У нас вы можете посмотреть бесплатно Django Tutorial: Adding Our Model To The Django Admin Site или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Check out our Django 2.0 tutorials at https://www.mastercode.online/courses... 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 Now that we have created our model and migrated the model to the database we are able to use admin site. First open your admin.py file in your text editor. The admin.py file lookes like. from django.contrib import admin Register your models here. Right now all this file does is import admin from django.contrib. The admin is a package that is included in contrib and this package requires two other packages auth and contenttypes. These two packages should be already be in the installed apps unless you removed them. The contrib is a directory which is included in the Django framework that contains many packages we can use in our Django project. Django likes to include many useful packages with their framework if you would like to see more visit https://docs.djangoproject.com/en/1.9... 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 For us to be able to access the model in our app we need to import the model into admin.py. This is pretty simple task. Take a look at the code below. from django.contrib import admin Register your models here. from .models import Lesson In the above code we are saying from .models which is the model contained in the same app import our class Lesson(which is a table). Now that we have added this line we are able to access the meta data in our models.py file. 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 To register the class we need to use the following code admin.site.register(class name) so in this case we would use the following code. from django.contrib import admin Register your models here. from .models import Lesson admin.site.register(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.