У нас вы можете посмотреть бесплатно Querysets and Django Shell или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
In this tutorial we will learn how to query the database. This step is very important and it may be a bit boring but if you understand how to query I database in Django you basically will never have any issues with django. We will use the django shell to query the database. We will grab post that we already created, create new post and even delete some post so lets get started. Let's fire up the django shell. 1. python3 manage.py shell 2. Since our post our tied into the user auth framework we will need to query that database as well so we will need to import the data base 'from django.contrib.auth.models import User'. Now we have access to the Users database. 3. Now we want to have access to our post model so we need to import that as well 'from blog.models import Post' 4. Now we want to have access to the Users post so we have to query the database for them. 'user = User.objects.get(username='admin')' 5. Now we want to create a new post. 'post = Post.objects.create(title='third post', slug='third-post', content='third post content', author=user)' 6. Now we have created a new post but we still have to commit it to the database which we will do with a simple onliner. 'post.save()' 7. How to do we get the post. Post.objects.all() 8. Modify objects post.title = 'This is a new title' post.save() 9. Order post in alphabetical order Post.objects.order_by('title') order post in reverse order Post.objects.order_by('-title') 10. delete a post post = Post.objects.get(id=2) post.delete()