{"id":346957,"date":"2023-03-18T21:00:48","date_gmt":"2023-03-18T21:00:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=346957"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=346957","title":{"rendered":"<span>Django REST. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u00ab\u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435\u00bb \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430<\/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<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0438 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &#171;\u041a\u043e\u043c\u043f\u0430\u043d\u0438\u0438&#187;, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435. \u041e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>Favorite<\/code>, \u044f\u0432\u043b\u044f\u044e\u0449\u0435\u0439\u0441\u044f \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0438\u043c \u0437\u0432\u0435\u043d\u043e\u043c, \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 ManyToManyField \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438  \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0435\u0439<\/p>\n<pre><code class=\"python\">from django.db import models from django.contrib.auth.models import User  class Company(models.Model):     name = models.CharField(max_length=100)  class Favorite(models.Model):     user = models.ForeignKey(User, on_delete=models.CASCADE)     company = models.ForeignKey(Company, on_delete=models.CASCADE)      class Meta:         unique_together = ('user', 'company') <\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 &#171;\u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435&#187; \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &#171;\u0417\u0430\u044f\u0432\u043a\u0438&#187;, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 Django \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 &#171;\u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435&#187; \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430.<\/p>\n<p>Django ContentType \u0438 GenericForeignKey &#8212; \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435  \u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044e\u0441\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 Django.<\/p>\n<p>ContentType &#8212; \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0442\u0438\u043f \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0430 \u043d\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f  \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f. \u041e\u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0438\u043c\u044f, \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>GenericForeignKey &#8212; \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438, \u043d\u0435 \u0437\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0432\u044b \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0435\u0441\u044c \u043d\u0430 ContentType \u0438 ID \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0432\u044f\u0437\u0430\u0442\u044c.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c GenericForeignKey, \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0432\u0430 \u043f\u043e\u043b\u044f \u0432 \u0432\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 &#8212; \u043f\u043e\u043b\u0435 ContentType \u0438 \u043f\u043e\u043b\u0435 Object ID. \u041f\u043e\u043b\u0435 ContentType \u0445\u0440\u0430\u043d\u0438\u0442 \u0442\u0438\u043f \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0430 \u043f\u043e\u043b\u0435 Object ID \u0445\u0440\u0430\u043d\u0438\u0442 ID \u044d\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c GenericForeignKey \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u043d\u0430 \u043f\u043e\u043b\u044f ContentType \u0438 Object ID.<\/p>\n<h3>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c <code>Favorite<\/code>.<\/p>\n<pre><code class=\"python\">from django.db import models from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType   class Favorite(models.Model):     user = models.ForeignKey(User, on_delete=models.CASCADE)     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)     object_id = models.PositiveIntegerField()     content_object = GenericForeignKey('content_type', 'object_id')      class Meta:         verbose_name = '\u0418\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435'         verbose_name_plural = '\u0418\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0435'         ordering = ['-id']         constraints = [             models.UniqueConstraint(                 fields=['user', 'object_id', 'content_type'],                 name='unique_user_content_type_object_id'             )         ] <\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435,<br \/> \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0435 <code>favorites = GenericRelation('Favorite')<\/code>. \u041f\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044e \u043a \u043f\u043e\u043b\u044e <code>favorites<\/code> \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 <code>Favorite<\/code>.<\/p>\n<pre><code class=\"python\">from django.contrib.contenttypes.fields import GenericRelation  class Application(models.Model):     name = models.CharField(max_length=100)     favorites = GenericRelation('Favorite')   class Company(models.Model):     name = models.CharField(max_length=100)     favorites = GenericRelation('Favorite') <\/code><\/pre>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\/\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435<\/h3>\n<p>\u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u0412\u044c\u044e-\u0441\u0435\u0442\u0443 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435, \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0443\u0442\u044c <code>...\/&lt;id>\/favorite\/<\/code>. \u041f\u0443\u0442\u044c <code>url<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 GET-\u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0445\u043e\u0447\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c\/\u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435, \u0442\u043e \u043c\u044b \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0445, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0435\u0449\u0435 \u043d\u0435\u0442 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0445, \u0434\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>ManageFavorite<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>favorite<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<\/p>\n<pre><code class=\"python\">from django.contrib.contenttypes.models import ContentType  class ManageFavorite:     @action(       detail=True,        methods=['get'],        url_path='favorite',        permission_classes=[IsAuthenticated, ]     )     def favorite(self, request, pk):         instance = self.get_object()         content_type = ContentType.objects.get_for_model(instance)         favorite_obj, created = Favorite.objects.get_or_create(             user=request.user, content_type=content_type, object_id=instance.id         )          if created:             return Response(                 {'message': '\u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435'},                 status=status.HTTP_201_CREATED             )         else:             favorite_obj.delete()             return Response(                 {'message': '\u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u0443\u0434\u0430\u043b\u0435\u043d \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e'},                 status=status.HTTP_200_OK             ) <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 <code>ManageFavorite<\/code> \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0438 \u0412\u044c\u044e-\u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439<br \/> \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435<\/p>\n<pre><code class=\"python\">class ApplicationViewSet(viewsets.ModelViewSet, ManageFavorite):     ...   class CompanyViewSet(viewsets.ModelViewSet, ManageFavorite):     ... <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0417\u0430\u044f\u0432\u043a\u0443 \u0441 id=2 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435.<\/p>\n<ul>\n<li>\n<p>GET-\u0437\u0430\u043f\u0440\u043e\u0441 <code>api\/applications\/2\/favorite\/<\/code><\/p>\n<\/li>\n<li>\n<p>status 201<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"json\">{     \"message\": \"\u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435\" } <\/code><\/pre>\n<p>\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0417\u0430\u044f\u0432\u043a\u0443 \u0441 id=2 \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e.<\/p>\n<ul>\n<li>\n<p>GET-\u0437\u0430\u043f\u0440\u043e\u0441 <code>api\/applications\/2\/favorite\/<\/code><\/p>\n<\/li>\n<li>\n<p>status 200<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"json\">{     \"message\": \"\u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u0443\u0434\u0430\u043b\u0435\u043d \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e\" } <\/code><\/pre>\n<h3>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u0441 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u044f is_favorite \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/h3>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 <code>ManageFavorite<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>annotate_qs_is_favorite_field<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <code>queryset<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0431\u0443\u043b\u0435\u0432\u043e \u043f\u043e\u043b\u0435 <code>is_favorite<\/code>, \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0449\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u044e\u0437\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435.<\/p>\n<pre><code class=\"python\">from django.contrib.contenttypes.models import ContentType from django.db.models import Exists, OuterRef  class ManageFavorite:     ...          def annotate_qs_is_favorite_field(self, queryset):         if self.request.user.is_authenticated:             is_favorite_subquery = Favorite.objects.filter(                 object_id=OuterRef('pk'),                  user=self.request.user,                  content_type=ContentType.objects.get_for_model(queryset.model)             )             queryset = queryset.annotate(is_favorite=Exists(is_favorite_subquery))         return queryset <\/code><\/pre>\n<p>\u0412\u043e \u0412\u044c\u044e-\u0441\u0435\u0442\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>get_queryset<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u0443\u044e<br \/> \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0434\u043b\u044f <code>queryset.<\/code><\/p>\n<pre><code class=\"python\">class ApplicationViewSet(viewsets.ModelViewSet, ManageFavorite):     serializer_class = ApplicationSerializer      def get_queryset(self):         queryset = Application.objects.all()         queryset = self.annotate_qs_is_favorite_field(queryset)         return queryset <\/code><\/pre>\n<p>\u0412 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u043e\u0435 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">class ApplicationSerializer(serializers.ModelSerializer):     is_favorite = serializers.BooleanField(read_only=True)      class Meta:         model = Application         fields = '__all__' <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0417\u0430\u044f\u0432\u043e\u043a.<\/p>\n<ul>\n<li>\n<p>GET-\u0437\u0430\u043f\u0440\u043e\u0441 <code>api\/applications\/<\/code><\/p>\n<\/li>\n<li>\n<p>status 200<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"json\">[     {         \"id\": 5,         \"is_favorite\": false,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 5\"     },     {         \"id\": 4,         \"is_favorite\": true,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 4\"     },     {         \"id\": 3,         \"is_favorite\": true,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 3\"     },     {         \"id\": 2,         \"is_favorite\": false,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 2\"     } ] <\/code><\/pre>\n<h3>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e<\/h3>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 <code>ManageFavorite<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>favorites<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043f\u0443\u0442\u044c <code>...\/favorites\/<\/code>. \u041f\u0443\u0442\u044c <code>url<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 GET-\u0437\u0430\u043f\u0440\u043e\u0441. \u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 <code>queryset<\/code> \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u043b\u0435\u043c <code>is_favorite<\/code>, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>True<\/code>.<\/p>\n<pre><code class=\"python\">class ManageFavorite:     ...      @action(         detail=False,         methods=['get'],         url_path='favorites',         permission_classes=[IsAuthenticated, ]     )     def favorites(self, request):         queryset = self.get_queryset().filter(is_favorite=True)         serializer_class = self.get_serializer_class()         serializer = serializer_class(queryset, many=True)         return Response(serializer.data, status=status.HTTP_200_OK) <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0417\u0430\u044f\u0432\u043e\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435.<\/p>\n<ul>\n<li>\n<p>GET-\u0437\u0430\u043f\u0440\u043e\u0441 <code>api\/applications\/favorites\/<\/code><\/p>\n<\/li>\n<li>\n<p>status 200<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"json\">[     {         \"id\": 4,         \"is_favorite\": true,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 4\"     },     {         \"id\": 3,         \"is_favorite\": true,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 3\"     } ] <\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 ContentType \u0438 GenericForeignKey \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u0433\u0438\u0431\u043a\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 Django, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044e\u0441\u043d\u044b\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044e\u0449\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/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\/post\/723300\/\"> https:\/\/habr.com\/ru\/post\/723300\/<\/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<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0438 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &#171;\u041a\u043e\u043c\u043f\u0430\u043d\u0438\u0438&#187;, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435. \u041e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>Favorite<\/code>, \u044f\u0432\u043b\u044f\u044e\u0449\u0435\u0439\u0441\u044f \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0438\u043c \u0437\u0432\u0435\u043d\u043e\u043c, \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 ManyToManyField \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438  \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0435\u0439<\/p>\n<pre><code class=\"python\">from django.db import models from django.contrib.auth.models import User  class Company(models.Model):     name = models.CharField(max_length=100)  class Favorite(models.Model):     user = models.ForeignKey(User, on_delete=models.CASCADE)     company = models.ForeignKey(Company, on_delete=models.CASCADE)      class Meta:         unique_together = ('user', 'company') <\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 &#171;\u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435&#187; \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &#171;\u0417\u0430\u044f\u0432\u043a\u0438&#187;, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 Django \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 &#171;\u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435&#187; \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430.<\/p>\n<p>Django ContentType \u0438 GenericForeignKey &#8212; \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435  \u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044e\u0441\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 Django.<\/p>\n<p>ContentType &#8212; \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0442\u0438\u043f \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0430 \u043d\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f  \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f. \u041e\u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0438\u043c\u044f, \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>GenericForeignKey &#8212; \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438, \u043d\u0435 \u0437\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0432\u044b \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0435\u0441\u044c \u043d\u0430 ContentType \u0438 ID \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0432\u044f\u0437\u0430\u0442\u044c.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c GenericForeignKey, \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0432\u0430 \u043f\u043e\u043b\u044f \u0432 \u0432\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 &#8212; \u043f\u043e\u043b\u0435 ContentType \u0438 \u043f\u043e\u043b\u0435 Object ID. \u041f\u043e\u043b\u0435 ContentType \u0445\u0440\u0430\u043d\u0438\u0442 \u0442\u0438\u043f \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0430 \u043f\u043e\u043b\u0435 Object ID \u0445\u0440\u0430\u043d\u0438\u0442 ID \u044d\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c GenericForeignKey \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u043d\u0430 \u043f\u043e\u043b\u044f ContentType \u0438 Object ID.<\/p>\n<h3>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c <code>Favorite<\/code>.<\/p>\n<pre><code class=\"python\">from django.db import models from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType   class Favorite(models.Model):     user = models.ForeignKey(User, on_delete=models.CASCADE)     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)     object_id = models.PositiveIntegerField()     content_object = GenericForeignKey('content_type', 'object_id')      class Meta:         verbose_name = '\u0418\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435'         verbose_name_plural = '\u0418\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0435'         ordering = ['-id']         constraints = [             models.UniqueConstraint(                 fields=['user', 'object_id', 'content_type'],                 name='unique_user_content_type_object_id'             )         ] <\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435,<br \/> \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0435 <code>favorites = GenericRelation('Favorite')<\/code>. \u041f\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044e \u043a \u043f\u043e\u043b\u044e <code>favorites<\/code> \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 <code>Favorite<\/code>.<\/p>\n<pre><code class=\"python\">from django.contrib.contenttypes.fields import GenericRelation  class Application(models.Model):     name = models.CharField(max_length=100)     favorites = GenericRelation('Favorite')   class Company(models.Model):     name = models.CharField(max_length=100)     favorites = GenericRelation('Favorite') <\/code><\/pre>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\/\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435<\/h3>\n<p>\u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u0412\u044c\u044e-\u0441\u0435\u0442\u0443 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435, \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0443\u0442\u044c <code>...\/&lt;id>\/favorite\/<\/code>. \u041f\u0443\u0442\u044c <code>url<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 GET-\u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0445\u043e\u0447\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c\/\u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435, \u0442\u043e \u043c\u044b \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0445, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0435\u0449\u0435 \u043d\u0435\u0442 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0445, \u0434\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>ManageFavorite<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>favorite<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<\/p>\n<pre><code class=\"python\">from django.contrib.contenttypes.models import ContentType  class ManageFavorite:     @action(       detail=True,        methods=['get'],        url_path='favorite',        permission_classes=[IsAuthenticated, ]     )     def favorite(self, request, pk):         instance = self.get_object()         content_type = ContentType.objects.get_for_model(instance)         favorite_obj, created = Favorite.objects.get_or_create(             user=request.user, content_type=content_type, object_id=instance.id         )          if created:             return Response(                 {'message': '\u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435'},                 status=status.HTTP_201_CREATED             )         else:             favorite_obj.delete()             return Response(                 {'message': '\u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u0443\u0434\u0430\u043b\u0435\u043d \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e'},                 status=status.HTTP_200_OK             ) <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 <code>ManageFavorite<\/code> \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0438 \u0412\u044c\u044e-\u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439<br \/> \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435<\/p>\n<pre><code class=\"python\">class ApplicationViewSet(viewsets.ModelViewSet, ManageFavorite):     ...   class CompanyViewSet(viewsets.ModelViewSet, ManageFavorite):     ... <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0417\u0430\u044f\u0432\u043a\u0443 \u0441 id=2 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435.<\/p>\n<ul>\n<li>\n<p>GET-\u0437\u0430\u043f\u0440\u043e\u0441 <code>api\/applications\/2\/favorite\/<\/code><\/p>\n<\/li>\n<li>\n<p>status 201<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"json\">{     \"message\": \"\u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435\" } <\/code><\/pre>\n<p>\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0417\u0430\u044f\u0432\u043a\u0443 \u0441 id=2 \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e.<\/p>\n<ul>\n<li>\n<p>GET-\u0437\u0430\u043f\u0440\u043e\u0441 <code>api\/applications\/2\/favorite\/<\/code><\/p>\n<\/li>\n<li>\n<p>status 200<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"json\">{     \"message\": \"\u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u0443\u0434\u0430\u043b\u0435\u043d \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e\" } <\/code><\/pre>\n<h3>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u0441 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u044f is_favorite \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/h3>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 <code>ManageFavorite<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>annotate_qs_is_favorite_field<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <code>queryset<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0431\u0443\u043b\u0435\u0432\u043e \u043f\u043e\u043b\u0435 <code>is_favorite<\/code>, \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0449\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u044e\u0437\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435.<\/p>\n<pre><code class=\"python\">from django.contrib.contenttypes.models import ContentType from django.db.models import Exists, OuterRef  class ManageFavorite:     ...          def annotate_qs_is_favorite_field(self, queryset):         if self.request.user.is_authenticated:             is_favorite_subquery = Favorite.objects.filter(                 object_id=OuterRef('pk'),                  user=self.request.user,                  content_type=ContentType.objects.get_for_model(queryset.model)             )             queryset = queryset.annotate(is_favorite=Exists(is_favorite_subquery))         return queryset <\/code><\/pre>\n<p>\u0412\u043e \u0412\u044c\u044e-\u0441\u0435\u0442\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>get_queryset<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u0443\u044e<br \/> \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0434\u043b\u044f <code>queryset.<\/code><\/p>\n<pre><code class=\"python\">class ApplicationViewSet(viewsets.ModelViewSet, ManageFavorite):     serializer_class = ApplicationSerializer      def get_queryset(self):         queryset = Application.objects.all()         queryset = self.annotate_qs_is_favorite_field(queryset)         return queryset <\/code><\/pre>\n<p>\u0412 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u043e\u0435 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">class ApplicationSerializer(serializers.ModelSerializer):     is_favorite = serializers.BooleanField(read_only=True)      class Meta:         model = Application         fields = '__all__' <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0417\u0430\u044f\u0432\u043e\u043a.<\/p>\n<ul>\n<li>\n<p>GET-\u0437\u0430\u043f\u0440\u043e\u0441 <code>api\/applications\/<\/code><\/p>\n<\/li>\n<li>\n<p>status 200<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"json\">[     {         \"id\": 5,         \"is_favorite\": false,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 5\"     },     {         \"id\": 4,         \"is_favorite\": true,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 4\"     },     {         \"id\": 3,         \"is_favorite\": true,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 3\"     },     {         \"id\": 2,         \"is_favorite\": false,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 2\"     } ] <\/code><\/pre>\n<h3>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e<\/h3>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 <code>ManageFavorite<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>favorites<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043f\u0443\u0442\u044c <code>...\/favorites\/<\/code>. \u041f\u0443\u0442\u044c <code>url<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 GET-\u0437\u0430\u043f\u0440\u043e\u0441. \u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 <code>queryset<\/code> \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u043b\u0435\u043c <code>is_favorite<\/code>, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>True<\/code>.<\/p>\n<pre><code class=\"python\">class ManageFavorite:     ...      @action(         detail=False,         methods=['get'],         url_path='favorites',         permission_classes=[IsAuthenticated, ]     )     def favorites(self, request):         queryset = self.get_queryset().filter(is_favorite=True)         serializer_class = self.get_serializer_class()         serializer = serializer_class(queryset, many=True)         return Response(serializer.data, status=status.HTTP_200_OK) <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0417\u0430\u044f\u0432\u043e\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435.<\/p>\n<ul>\n<li>\n<p>GET-\u0437\u0430\u043f\u0440\u043e\u0441 <code>api\/applications\/favorites\/<\/code><\/p>\n<\/li>\n<li>\n<p>status 200<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"json\">[     {         \"id\": 4,         \"is_favorite\": true,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 4\"     },     {         \"id\": 3,         \"is_favorite\": true,         \"name\": \"\u0417\u0430\u044f\u0432\u043a\u0430 3\"     } ] <\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 ContentType \u0438 GenericForeignKey \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u0433\u0438\u0431\u043a\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 Django, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044e\u0441\u043d\u044b\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044e\u0449\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/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\/post\/723300\/\"> https:\/\/habr.com\/ru\/post\/723300\/<\/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-346957","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346957","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=346957"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346957\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=346957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=346957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=346957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}