{"id":394408,"date":"2024-06-29T11:35:53","date_gmt":"2024-06-29T11:35:53","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=394408"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=394408","title":{"rendered":"<span>\u041d\u0435 \u0441\u0430\u043c\u044b\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b Django ORM<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/33a\/d9d\/a53\/33ad9da53c1b0094663862eb092dded0.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/33a\/d9d\/a53\/33ad9da53c1b0094663862eb092dded0.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e Django \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 ORM \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0438\u0441\u0430\u0442\u044c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b. \u041e\u0434\u043d\u0430\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0430\u0441 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 <code>filter()<\/code><em>, <\/em><code>get()<\/code><em>, <\/em><code>update()<\/code> \u0438 <code>delete()<\/code> \u0438\u0437 Django ORM.<\/p>\n<p>\u0412 Django ORM \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u043f\u0446\u0438\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435 \u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0432\u0430\u043c \u043f\u0440\u043e \u043d\u0435\u0433\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443.<\/p>\n<ul>\n<li>\n<p><code>exclude()<\/code><\/p>\n<\/li>\n<li>\n<p><code>values()<\/code><\/p>\n<\/li>\n<li>\n<p><code>values_list()<\/code><\/p>\n<\/li>\n<li>\n<p><code>select_related()<\/code><\/p>\n<\/li>\n<li>\n<p><code>order_by()<\/code><\/p>\n<\/li>\n<li>\n<p><code>exists()<\/code><\/p>\n<\/li>\n<li>\n<p><code>count()<\/code><\/p>\n<\/li>\n<li>\n<p><code>first() and last()<\/code><\/p>\n<\/li>\n<li>\n<p><code>in_bulk()<\/code><\/p>\n<\/li>\n<li>\n<p><code>explain()<\/code><\/p>\n<\/li>\n<li>\n<p><code>latest()<\/code><\/p>\n<\/li>\n<li>\n<p><code>earliest()<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u042f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>Student<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043b\u0430\u0441\u0441 <code>Student<\/code> \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <em>models.py<\/em>.<\/p>\n<pre><code class=\"python\">class Student(models.Model):     name = models.CharField(max_length=100)     grade = models.IntegerField()     section = models.CharField(max_length=10)     school = models.ForeignKey(School, on_delete=models.CASCADE)     blood_group = models.CharField(max_length=10)     mobile = models.CharField(max_length=20)     address = models.TextField()    def __str__(self):         return self.name<\/code><\/pre>\n<p>\u0423 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>Student<\/code> \u0435\u0441\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0435\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>School<\/code>.<\/p>\n<pre><code class=\"python\">class School(models.Model):     name = models.CharField(max_length=100)     email = models.EmailField(null=True, blank=True)     address = models.TextField()    def __str__(self):         return self.name<\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<h4>1. exclude()<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 &#8212; <code>exclude()<\/code>. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u0435\u0437 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0430\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>Student<\/code> \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c 4 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 <code>all()<\/code>.<\/p>\n<pre><code>>>> queryset = Student.objects.all() >>> queryset &lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: Eva Smith>, &lt;Student: Jessie Smith>, &lt;Student: John David>]><\/code><\/pre>\n<p>\u041c\u043d\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e Eva Smith \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430 \u0432 \u0432\u044b\u0434\u0430\u0447\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0432\u044b\u0437\u043e\u0432\u0443 \u043c\u0435\u0442\u043e\u0434 <code>exclude()<\/code> \u0441 \u0435\u0435 \u0438\u043c\u0435\u043d\u0435\u043c \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 <code>Student<\/code>.<\/p>\n<pre><code>>>> queryset = Student.objects.exclude(name='Eva Smith') >>> queryset &lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: Jessie Smith>, &lt;Student: John David>]><\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0435 \u0438\u043c\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435.<\/p>\n<h4>2. Values()<\/h4>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 &#8212; \u043c\u0435\u0442\u043e\u0434 <code>values()<\/code>. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 Python \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>QuerySet<\/code>.<\/p>\n<pre><code>>>> Student.objects.values()&lt;QuerySet [{'id': 1, 'name': 'Regina Johnson', 'grade': 10, 'section': 'A', 'school_id': 1, 'blood_group': 'A+', 'mobile': '9791684645', 'address': '93 Jessica Ln, Depew, NY, 14043'}, {'id': 3, 'name': 'Eva Smith', 'grade': 12, 'section': 'A', 'school_id': 1, 'blood_group': 'A1+', 'mobile': '8907896543', 'address': '2012 Walnut Ave #J, Ceres, CA, 95307'}, {'id': 4, 'name': 'Jessie Smith', 'grade': 12, 'section': 'A', 'school_id': 1, 'blood_group': 'A1+', 'mobile': '8907896543', 'address': '503 Courtney Dr, Brusly, LA, 70719'}, {'id': 5, 'name': 'John David', 'grade': 12, 'section': 'A', 'school_id': 1, 'blood_group': 'A1+', 'mobile': '2675431231', 'address': '34 Leaman Pl, Lynbrook, NY, 11563'}]><\/code><\/pre>\n<p>\u0415\u0449\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0438\u0445 \u0438\u043c\u0435\u043d\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0443 <code>values()<\/code><em>.<\/em> \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e <code>id<\/code><em> <\/em>\u0438 <code>name<\/code> \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432. \u042f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a.<\/p>\n<pre><code>>>> Student.objects.values('id', 'name')&lt;QuerySet [{'id': 1, 'name': 'Regina Johnson'}, {'id': 3, 'name': 'Eva Smith'}, {'id': 4, 'name': 'Jessie Smith'}, {'id': 5, 'name': 'John David'}]><\/code><\/pre>\n<h4>3. values_list()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>values_list()<\/code> \u0441\u0445\u043e\u0436 \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>values()<\/code>, \u043d\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u0440\u0442\u0435\u0436\u0438.<\/p>\n<pre><code>>>> Student.objects.values_list('id', 'name')&lt;QuerySet [(1, 'Regina Johnson'), (3, 'Eva Smith'), (4, 'Jessie Smith'), (5, 'John David')]><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043f\u0438\u0441\u043e\u043a, \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043e\u0440\u0442\u0435\u0436\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0443 <code>values_list()<\/code> \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>flat=True<\/code>. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435 <code>name<\/code> \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430, \u044f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code>>>> Student.objects.values_list('name', flat=True)&lt;QuerySet ['Regina Johnson', 'Eva Smith', 'Jessie Smith', 'John David']><\/code><\/pre>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u041c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u043e\u043b\u0435\u043c. \u0415\u0441\u043b\u0438 \u0432\u044b \u0443\u043a\u0430\u0436\u0435\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 &#8212; \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435.<\/em><\/p>\n<pre><code>>>> Student.objects.values_list('id', 'name', flat=True) TypeError: 'flat' is not valid when values_list is called with more than one field.<\/code><\/pre>\n<h4>4. select_related()<\/h4>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f. \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u043c\u043e\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>Student<\/code> \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043a\u043b\u044e\u0447\u043e\u043c \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>School<\/code>. \u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u0439 \u0448\u043a\u043e\u043b\u0435 \u0443\u0447\u0438\u0442\u0441\u044f \u0441\u0442\u0443\u0434\u0435\u043d\u0442, \u044f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<pre><code>>>> student = Student.objects.get(pk=1) >>> student.school &lt;School: Montfort><\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430, \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u0435\u0433\u043e <code>id<\/code><em> <\/em>\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>Student<\/code>. \u0417\u0430\u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0448\u043a\u043e\u043b\u0443, \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u043f\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0445\u043e\u0434 \u043f\u043e \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/em><\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043d\u0430\u0448\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043d\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0432\u044f\u0437\u0435\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043f\u043e\u043c\u0435\u0440\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u043e\u0439.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>select_related()<\/code> \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0443\u0442\u0435\u043c \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043d\u0435\u0439.<\/p>\n<pre><code>>>> student = Student.objects.select_related('school').get(pk=1) >>> student.school # school has already been retrieved. Database is not hit again. &lt;School: Montfort><\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e \u0448\u043a\u043e\u043b\u0443 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<h4>5. order_by()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>order_by()<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0434\u0430\u0447\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u044b\u0434\u0430\u044e\u0442\u0441\u044f \u0441 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u043f\u043e \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u0430\u043c (<em>id<\/em>). \u0415\u0441\u043b\u0438 \u044f \u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0439 QuerySet \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u043b\u0441\u044f \u043f\u043e \u0438\u043c\u0435\u043d\u0438, \u044f \u043c\u043e\u0433\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u0435 <code>name<\/code> \u043c\u0435\u0442\u043e\u0434\u0443 <code>order_by()<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u044f \u0437\u0430\u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0439 QuerySet \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u043b\u0441\u044f \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f, \u044f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e.<\/p>\n<pre><code>>>> Student.objects.order_by('name')&lt;QuerySet [&lt;Student: Eva Smith>, &lt;Student: Jessie Smith>, &lt;Student: John David>, &lt;Student: Regina Johnson>]><\/code><\/pre>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code>>>> Student.objects.order_by('-name')&lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: John David>, &lt;Student: Jessie Smith>, &lt;Student: Eva Smith>]><\/code><\/pre>\n<p>\u041e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>name<\/code> \u2013 \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u0442\u0440\u044e\u043a.<\/p>\n<h4>6. exists()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>exists()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>True<\/code>, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 QuerySet \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>False<\/code>, \u0435\u0441\u043b\u0438 QuerySet \u043f\u0443\u0441\u0442\u043e\u0439.<\/p>\n<pre><code>>>> Student.objects.filter(name='Regina Johnson').exists() True >>> Student.objects.filter(name='Regina David').exists() False<\/code><\/pre>\n<p>\u0412 \u043c\u043e\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043a\u0430 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 Regina Johnson, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434 <code>exists()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>True<\/code> \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u00abRegina Johnson\u00bb \u0438 <code>False<\/code> \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445.<\/p>\n<h4>7. count()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>count()<\/code> \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 QuerySet. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0432\u0441\u0435\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code>>>> Student.objects.count() 4<\/code><\/pre>\n<p>\u0418\u043b\u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c:<\/p>\n<pre><code>>>> Student.objects.filter(name='Regina Johnson').count() 1<\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>count()<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u0443 <code>aggregate()<\/code>, \u043d\u043e \u0443 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0441\u0442\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0438 \u043e\u043d, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043c\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h4>8. first() and last()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>first()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 QuerySet.<\/p>\n<pre><code>>>> Student.objects.all() &lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: Eva Smith>, &lt;Student: Jessie Smith>, &lt;Student: John David>]>>>> Student.objects.all().first() &lt;Student: Regina Johnson><\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>last()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 QuerySet.<\/p>\n<pre><code>>>> Student.objects.all() &lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: Eva Smith>, &lt;Student: Jessie Smith>, &lt;Student: John David>]>>>> Student.objects.all().last() &lt;Student: John David><\/code><\/pre>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e QuerySet \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0441\u043f\u0438\u0441\u043e\u043a, \u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0432\u0438\u0434\u0430 <code>queryset[0]<\/code>, \u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0447\u0435\u0440\u0435\u0437 <code>queryset[-1]<\/code><em> <\/em>\u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u0435\u0442\u043e\u0434 <code>last()<\/code> \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043a\u0441\u0442\u0430\u0442\u0438.<\/p>\n<pre><code>>>> Student.objects.all()[0] &lt;Student: Regina Johnson> >>> Student.objects.all()[-1]    \"Negative indexing is not supported.\" AssertionError: Negative indexing is not supported.<\/code><\/pre>\n<h4>9. in_bulk()<\/h4>\n<p><code>in_bulk()<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>id<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439<em> <\/em><code>id<\/code> \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u0442\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0435\u0442\u043e\u0434\u0443 <code>in_bulk()<\/code>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u0441 <em>id <\/em>1 \u0438 4, \u044f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a.<\/p>\n<pre><code>>>> students = Student.objects.in_bulk([1, 4]) >>> students[1].name 'Regina Johnson' >>> students[4].name 'Jessie Smith'<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u044f \u043c\u043e\u0433\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>id<\/code><em> <\/em>\u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430.<\/p>\n<h4>10. explain()<\/h4>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043b\u0430\u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f QuerySet. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<pre><code>>>> Student.objects.filter(pk=1).explain() '2 0 0 SEARCH TABLE student_student USING INTEGER PRIMARY KEY (rowid=?)'<\/code><\/pre>\n<h4>11. latest()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>latest()<\/code> \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u0443 <code>last()<\/code>. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u043b\u043e\u0433\u0430, \u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a.<\/p>\n<pre><code>>>> Blog.objects.latest('updated_at') &lt;Blog: Blog object (17)><\/code><\/pre>\n<p>\u0427\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438:<\/p>\n<pre><code>>>> Blog.objects.all().order_by('updated_at').last() &lt;Blog: Blog object (17)><\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>latest()<\/code><em> <\/em>\u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u043d \u043f\u043e\u043b\u0435\u0439.<\/p>\n<pre><code>>>> Blog.objects.latest('updated_at', '-created_at') &lt;Blog: Blog object (17)><\/code><\/pre>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0415\u0441\u043b\u0438 \u0432\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u0435\u0442\u0430-\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0432\u043e\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f.<\/em><\/p>\n<h4>12. earliest()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>earliest()<\/code> \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u0443 <code>first()<\/code> \u0438 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u0443 <code>latest()<\/code>.\u00a0<\/p>\n<p>\u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u043d \u043f\u043e\u043b\u0435\u0439 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<pre><code>>>> Blog.objects.earliest('updated_at') &lt;Blog: Blog object (17)><\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439. \u0423\u0434\u0430\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430!<\/p>\n<p><em>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438: <\/em><a href=\"https:\/\/docs.djangoproject.com\/en\/3.2\/ref\/models\/querysets\/\"><em>https:\/\/docs.djangoproject.com\/en\/3.2\/ref\/models\/querysets\/<\/em><\/a><\/p>\n<hr\/>\n<p>\u0412\u0441\u0435\u0445 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u043d\u0430 <a href=\"https:\/\/otus.pw\/bqED\/\">\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u0440\u043e\u043a<\/a> \u00ab\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 Django\u00bb. \u041d\u0430 \u0437\u0430\u043d\u044f\u0442\u0438\u0438 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430 Django: \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 requests, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Django-\u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/654081\/\"> https:\/\/habr.com\/ru\/articles\/654081\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e Django \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 ORM \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0438\u0441\u0430\u0442\u044c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b. \u041e\u0434\u043d\u0430\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0430\u0441 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 <code>filter()<\/code><em>, <\/em><code>get()<\/code><em>, <\/em><code>update()<\/code> \u0438 <code>delete()<\/code> \u0438\u0437 Django ORM.<\/p>\n<p>\u0412 Django ORM \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u043f\u0446\u0438\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435 \u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0432\u0430\u043c \u043f\u0440\u043e \u043d\u0435\u0433\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443.<\/p>\n<ul>\n<li>\n<p><code>exclude()<\/code><\/p>\n<\/li>\n<li>\n<p><code>values()<\/code><\/p>\n<\/li>\n<li>\n<p><code>values_list()<\/code><\/p>\n<\/li>\n<li>\n<p><code>select_related()<\/code><\/p>\n<\/li>\n<li>\n<p><code>order_by()<\/code><\/p>\n<\/li>\n<li>\n<p><code>exists()<\/code><\/p>\n<\/li>\n<li>\n<p><code>count()<\/code><\/p>\n<\/li>\n<li>\n<p><code>first() and last()<\/code><\/p>\n<\/li>\n<li>\n<p><code>in_bulk()<\/code><\/p>\n<\/li>\n<li>\n<p><code>explain()<\/code><\/p>\n<\/li>\n<li>\n<p><code>latest()<\/code><\/p>\n<\/li>\n<li>\n<p><code>earliest()<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u042f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>Student<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043b\u0430\u0441\u0441 <code>Student<\/code> \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <em>models.py<\/em>.<\/p>\n<pre><code class=\"python\">class Student(models.Model):     name = models.CharField(max_length=100)     grade = models.IntegerField()     section = models.CharField(max_length=10)     school = models.ForeignKey(School, on_delete=models.CASCADE)     blood_group = models.CharField(max_length=10)     mobile = models.CharField(max_length=20)     address = models.TextField()    def __str__(self):         return self.name<\/code><\/pre>\n<p>\u0423 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>Student<\/code> \u0435\u0441\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0435\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>School<\/code>.<\/p>\n<pre><code class=\"python\">class School(models.Model):     name = models.CharField(max_length=100)     email = models.EmailField(null=True, blank=True)     address = models.TextField()    def __str__(self):         return self.name<\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<h4>1. exclude()<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 &#8212; <code>exclude()<\/code>. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u0435\u0437 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0430\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>Student<\/code> \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c 4 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 <code>all()<\/code>.<\/p>\n<pre><code>>>> queryset = Student.objects.all() >>> queryset &lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: Eva Smith>, &lt;Student: Jessie Smith>, &lt;Student: John David>]><\/code><\/pre>\n<p>\u041c\u043d\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e Eva Smith \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430 \u0432 \u0432\u044b\u0434\u0430\u0447\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0432\u044b\u0437\u043e\u0432\u0443 \u043c\u0435\u0442\u043e\u0434 <code>exclude()<\/code> \u0441 \u0435\u0435 \u0438\u043c\u0435\u043d\u0435\u043c \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 <code>Student<\/code>.<\/p>\n<pre><code>>>> queryset = Student.objects.exclude(name='Eva Smith') >>> queryset &lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: Jessie Smith>, &lt;Student: John David>]><\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0435 \u0438\u043c\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435.<\/p>\n<h4>2. Values()<\/h4>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 &#8212; \u043c\u0435\u0442\u043e\u0434 <code>values()<\/code>. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 Python \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>QuerySet<\/code>.<\/p>\n<pre><code>>>> Student.objects.values()&lt;QuerySet [{'id': 1, 'name': 'Regina Johnson', 'grade': 10, 'section': 'A', 'school_id': 1, 'blood_group': 'A+', 'mobile': '9791684645', 'address': '93 Jessica Ln, Depew, NY, 14043'}, {'id': 3, 'name': 'Eva Smith', 'grade': 12, 'section': 'A', 'school_id': 1, 'blood_group': 'A1+', 'mobile': '8907896543', 'address': '2012 Walnut Ave #J, Ceres, CA, 95307'}, {'id': 4, 'name': 'Jessie Smith', 'grade': 12, 'section': 'A', 'school_id': 1, 'blood_group': 'A1+', 'mobile': '8907896543', 'address': '503 Courtney Dr, Brusly, LA, 70719'}, {'id': 5, 'name': 'John David', 'grade': 12, 'section': 'A', 'school_id': 1, 'blood_group': 'A1+', 'mobile': '2675431231', 'address': '34 Leaman Pl, Lynbrook, NY, 11563'}]><\/code><\/pre>\n<p>\u0415\u0449\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0438\u0445 \u0438\u043c\u0435\u043d\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0443 <code>values()<\/code><em>.<\/em> \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e <code>id<\/code><em> <\/em>\u0438 <code>name<\/code> \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432. \u042f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a.<\/p>\n<pre><code>>>> Student.objects.values('id', 'name')&lt;QuerySet [{'id': 1, 'name': 'Regina Johnson'}, {'id': 3, 'name': 'Eva Smith'}, {'id': 4, 'name': 'Jessie Smith'}, {'id': 5, 'name': 'John David'}]><\/code><\/pre>\n<h4>3. values_list()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>values_list()<\/code> \u0441\u0445\u043e\u0436 \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>values()<\/code>, \u043d\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u0440\u0442\u0435\u0436\u0438.<\/p>\n<pre><code>>>> Student.objects.values_list('id', 'name')&lt;QuerySet [(1, 'Regina Johnson'), (3, 'Eva Smith'), (4, 'Jessie Smith'), (5, 'John David')]><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043f\u0438\u0441\u043e\u043a, \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043e\u0440\u0442\u0435\u0436\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0443 <code>values_list()<\/code> \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>flat=True<\/code>. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435 <code>name<\/code> \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430, \u044f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code>>>> Student.objects.values_list('name', flat=True)&lt;QuerySet ['Regina Johnson', 'Eva Smith', 'Jessie Smith', 'John David']><\/code><\/pre>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u041c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u043e\u043b\u0435\u043c. \u0415\u0441\u043b\u0438 \u0432\u044b \u0443\u043a\u0430\u0436\u0435\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 &#8212; \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435.<\/em><\/p>\n<pre><code>>>> Student.objects.values_list('id', 'name', flat=True) TypeError: 'flat' is not valid when values_list is called with more than one field.<\/code><\/pre>\n<h4>4. select_related()<\/h4>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f. \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u043c\u043e\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>Student<\/code> \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043a\u043b\u044e\u0447\u043e\u043c \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>School<\/code>. \u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u0439 \u0448\u043a\u043e\u043b\u0435 \u0443\u0447\u0438\u0442\u0441\u044f \u0441\u0442\u0443\u0434\u0435\u043d\u0442, \u044f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<pre><code>>>> student = Student.objects.get(pk=1) >>> student.school &lt;School: Montfort><\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430, \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u0435\u0433\u043e <code>id<\/code><em> <\/em>\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>Student<\/code>. \u0417\u0430\u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0448\u043a\u043e\u043b\u0443, \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u043f\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0445\u043e\u0434 \u043f\u043e \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/em><\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043d\u0430\u0448\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043d\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0432\u044f\u0437\u0435\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043f\u043e\u043c\u0435\u0440\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u043e\u0439.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>select_related()<\/code> \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0443\u0442\u0435\u043c \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043d\u0435\u0439.<\/p>\n<pre><code>>>> student = Student.objects.select_related('school').get(pk=1) >>> student.school # school has already been retrieved. Database is not hit again. &lt;School: Montfort><\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e \u0448\u043a\u043e\u043b\u0443 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<h4>5. order_by()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>order_by()<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0434\u0430\u0447\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u044b\u0434\u0430\u044e\u0442\u0441\u044f \u0441 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u043f\u043e \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u0430\u043c (<em>id<\/em>). \u0415\u0441\u043b\u0438 \u044f \u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0439 QuerySet \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u043b\u0441\u044f \u043f\u043e \u0438\u043c\u0435\u043d\u0438, \u044f \u043c\u043e\u0433\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u0435 <code>name<\/code> \u043c\u0435\u0442\u043e\u0434\u0443 <code>order_by()<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u044f \u0437\u0430\u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0439 QuerySet \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u043b\u0441\u044f \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f, \u044f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e.<\/p>\n<pre><code>>>> Student.objects.order_by('name')&lt;QuerySet [&lt;Student: Eva Smith>, &lt;Student: Jessie Smith>, &lt;Student: John David>, &lt;Student: Regina Johnson>]><\/code><\/pre>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code>>>> Student.objects.order_by('-name')&lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: John David>, &lt;Student: Jessie Smith>, &lt;Student: Eva Smith>]><\/code><\/pre>\n<p>\u041e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>name<\/code> \u2013 \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u0442\u0440\u044e\u043a.<\/p>\n<h4>6. exists()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>exists()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>True<\/code>, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 QuerySet \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>False<\/code>, \u0435\u0441\u043b\u0438 QuerySet \u043f\u0443\u0441\u0442\u043e\u0439.<\/p>\n<pre><code>>>> Student.objects.filter(name='Regina Johnson').exists() True >>> Student.objects.filter(name='Regina David').exists() False<\/code><\/pre>\n<p>\u0412 \u043c\u043e\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043a\u0430 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 Regina Johnson, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434 <code>exists()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>True<\/code> \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u00abRegina Johnson\u00bb \u0438 <code>False<\/code> \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445.<\/p>\n<h4>7. count()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>count()<\/code> \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 QuerySet. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0432\u0441\u0435\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code>>>> Student.objects.count() 4<\/code><\/pre>\n<p>\u0418\u043b\u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c:<\/p>\n<pre><code>>>> Student.objects.filter(name='Regina Johnson').count() 1<\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>count()<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u0443 <code>aggregate()<\/code>, \u043d\u043e \u0443 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0441\u0442\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0438 \u043e\u043d, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043c\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h4>8. first() and last()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>first()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 QuerySet.<\/p>\n<pre><code>>>> Student.objects.all() &lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: Eva Smith>, &lt;Student: Jessie Smith>, &lt;Student: John David>]>>>> Student.objects.all().first() &lt;Student: Regina Johnson><\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>last()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 QuerySet.<\/p>\n<pre><code>>>> Student.objects.all() &lt;QuerySet [&lt;Student: Regina Johnson>, &lt;Student: Eva Smith>, &lt;Student: Jessie Smith>, &lt;Student: John David>]>>>> Student.objects.all().last() &lt;Student: John David><\/code><\/pre>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e QuerySet \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0441\u043f\u0438\u0441\u043e\u043a, \u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0432\u0438\u0434\u0430 <code>queryset[0]<\/code>, \u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0447\u0435\u0440\u0435\u0437 <code>queryset[-1]<\/code><em> <\/em>\u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u0435\u0442\u043e\u0434 <code>last()<\/code> \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043a\u0441\u0442\u0430\u0442\u0438.<\/p>\n<pre><code>>>> Student.objects.all()[0] &lt;Student: Regina Johnson> >>> Student.objects.all()[-1]    \"Negative indexing is not supported.\" AssertionError: Negative indexing is not supported.<\/code><\/pre>\n<h4>9. in_bulk()<\/h4>\n<p><code>in_bulk()<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>id<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439<em> <\/em><code>id<\/code> \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u0442\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0435\u0442\u043e\u0434\u0443 <code>in_bulk()<\/code>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u0441 <em>id <\/em>1 \u0438 4, \u044f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a.<\/p>\n<pre><code>>>> students = Student.objects.in_bulk([1, 4]) >>> students[1].name 'Regina Johnson' >>> students[4].name 'Jessie Smith'<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u044f \u043c\u043e\u0433\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>id<\/code><em> <\/em>\u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430.<\/p>\n<h4>10. explain()<\/h4>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043b\u0430\u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f QuerySet. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<pre><code>>>> Student.objects.filter(pk=1).explain() '2 0 0 SEARCH TABLE student_student USING INTEGER PRIMARY KEY (rowid=?)'<\/code><\/pre>\n<h4>11. latest()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>latest()<\/code> \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u0443 <code>last()<\/code>. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u043b\u043e\u0433\u0430, \u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a.<\/p>\n<pre><code>>>> Blog.objects.latest('updated_at') &lt;Blog: Blog object (17)><\/code><\/pre>\n<p>\u0427\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438:<\/p>\n<pre><code>>>> Blog.objects.all().order_by('updated_at').last() &lt;Blog: Blog object (17)><\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>latest()<\/code><em> <\/em>\u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u043d \u043f\u043e\u043b\u0435\u0439.<\/p>\n<pre><code>>>> Blog.objects.latest('updated_at', '-created_at') &lt;Blog: Blog object (17)><\/code><\/pre>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0415\u0441\u043b\u0438 \u0432\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u0435\u0442\u0430-\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0432\u043e\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f.<\/em><\/p>\n<h4>12. earliest()<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>earliest()<\/code> \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u0443 <code>first()<\/code> \u0438 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u0443 <code>latest()<\/code>.\u00a0<\/p>\n<p>\u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u043d \u043f\u043e\u043b\u0435\u0439 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<pre><code>>>> Blog.objects.earliest('updated_at') &lt;Blog: Blog object (17)><\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439. \u0423\u0434\u0430\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430!<\/p>\n<p><em>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438: <\/em><a href=\"https:\/\/docs.djangoproject.com\/en\/3.2\/ref\/models\/querysets\/\"><em>https:\/\/docs.djangoproject.com\/en\/3.2\/ref\/models\/querysets\/<\/em><\/a><\/p>\n<hr\/>\n<p>\u0412\u0441\u0435\u0445 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u043d\u0430 <a href=\"https:\/\/otus.pw\/bqED\/\">\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u0440\u043e\u043a<\/a> \u00ab\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 Django\u00bb. \u041d\u0430 \u0437\u0430\u043d\u044f\u0442\u0438\u0438 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430 Django: \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 requests, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Django-\u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/654081\/\"> https:\/\/habr.com\/ru\/articles\/654081\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-394408","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/394408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=394408"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/394408\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=394408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=394408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=394408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}