{"id":304772,"date":"2020-06-03T15:01:07","date_gmt":"2020-06-03T15:01:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=304772"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=304772","title":{"rendered":"Django: \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/505156\/\">\n<h1 id=\"problema\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h1>\n<p>  <\/p>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 API \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0432\u0435\u0431-\u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u044f \u0432\u0437\u044f\u043b \u0441\u0432\u043e\u0439 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u0441\u0442\u0435\u043a:<\/p>\n<p>  <\/p>\n<ul>\n<li>Django<\/li>\n<li>django-rest-framework<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u043e \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0441\u0442\u043e\u044f\u043b\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u0440\u0438\u0432\u044b\u0447\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u0443 User \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 (\u0418\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c, \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a). \u0418 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 \u0434\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u043b\u043d\u043e\u043c\u043e\u0447\u0438\u044f \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043e\u0434\u043d\u0438\u043c\u0438 \u0438 \u0442\u0435\u043c\u0438 \u0436\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043d\u0435 \u0437\u0430\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u043e\u043b\u0438, \u0447\u0442\u043e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0432\u0438\u0434\u0443 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c: \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 email \u0438\u043b\u0438 \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043e\u043f\u0438\u0448\u0435\u043c \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0438\u0435 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u2013 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439.<\/li>\n<li>\u041a\u0430\u043a \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439.<\/li>\n<li>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0434\u043d\u0438\u043c \u0442\u0435\u043c \u0436\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c \u043e\u0442 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0441\u0432\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043b\u043e\u0436\u0438\u043b\u0441\u044f \u0438\u0437 \u0443\u0436\u0435 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0432\u044b\u0447\u0435\u043a \u043f\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 Django-\u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e\u0435 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"odin-polzovatel---neskolko-profiley\">\u041e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u2014 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439<\/h1>\n<p>  <\/p>\n<p>\u041d\u0430\u0434 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u044f \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0434\u0443\u043c\u0430\u043b \u0438 \u0448\u0435\u043b \u043f\u043e \u043e\u043f\u044b\u0442\u0443 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u0434\u0430 \u0438 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u0438\u0441\u0430\u043d, \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 (<a href=\"https:\/\/docs.djangoproject.com\/en\/3.0\/topics\/auth\/customizing\/#extending-the-existing-user-model\">https:\/\/docs.djangoproject.com\/en\/3.0\/topics\/auth\/customizing\/#extending-the-existing-user-model<\/a>)<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># models.py class User(AbstractUser):     username = None     email = models.EmailField(unique=True, verbose_name=_(&quot;email&quot;))     phone = models.CharField(unique=True, max_length=11, verbose_name=_(&quot;phone&quot;))     ...     USERNAME_FIELD = &quot;email&quot;     EMAIL_FIELD = &quot;email&quot;     ...  class Employee(models.Model):     ...     user = models.OneToOneField(         &quot;user.User&quot;,         on_delete=models.CASCADE,         related_name=&quot;employee&quot;,         verbose_name=_(&quot;user&quot;),     )  class Company(models.Model):     ...  class Member(models.Model):     is_owner = models.BooleanField(default=False, verbose_name=_(&quot;owner&quot;))     is_manager = models.BooleanField(default=False, verbose_name=_(&quot;manager&quot;))     is_active = models.BooleanField(default=True)     user = models.OneToOneField(         &quot;user.User&quot;,         on_delete=models.CASCADE,         related_name=&quot;member&quot;,         verbose_name=_(&quot;user&quot;),     )     company = models.ForeignKey(         &quot;user.Company&quot;,         on_delete=models.CASCADE,         related_name=&quot;members&quot;,         verbose_name=_(&quot;company&quot;),     )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043e\u0442 0 \u0434\u043e 2-\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 (\u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0418\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f, \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0430).<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0443\u044e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u044f \u043f\u0440\u0438\u043d\u044f\u043b \u043a\u0430\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u0441\u0447\u0438\u0442\u0430\u043b, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043e\u0448\u0438\u0431\u043e\u043a \u0434\u043e\u043f\u0443\u0449\u0435\u043d\u043e \u043d\u0435 \u0431\u044b\u043b\u043e.<\/p>\n<p>  <\/p>\n<h1 id=\"kak-organizovat-prava-kazhdogo-iz-profiley\">\u041a\u0430\u043a \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439<\/h1>\n<p>  <\/p>\n<p>\u042d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u044f \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0448\u0430\u043b \u043f\u043e \u043e\u043f\u044b\u0442\u0443 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432 Custom Permissions \u043e\u0442 drf (<a href=\"https:\/\/www.django-rest-framework.org\/api-guide\/permissions\/#custom-permissions\">https:\/\/www.django-rest-framework.org\/api-guide\/permissions\/#custom-permissions<\/a>).<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u044c. \u041d\u043e \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0438 \u0447\u0435\u0440\u0435\u0437 \u0434\u0436\u0430\u043d\u0433\u043e \u043f\u0435\u0440\u043c\u0438\u0448\u043d\u044b.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># permissions.py from rest_framework.permissions import BasePermission  class EmployeeOnly(BasePermission):     def has_permission(self, request, view):         return request.user.is_authenticated and hasattr(request.user, &quot;employee&quot;)  class CompanyManagerOnly(BasePermission):     def has_permission(self, request, view):         return (             request.user.is_authenticated             and hasattr(request.user, &quot;member&quot;)             and request.user.member.is_active             and request.user.member.is_manager         )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0441 \u043b\u044e\u0431\u044b\u043c \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0439 permission<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># permissions.py class EmployeeAndCompanyManagerOnly(BasePermission):     def has_permission(self, request, view):         return request.user.is_authenticated and (             hasattr(request.user, &quot;employee&quot;)             or (                 hasattr(request.user, &quot;member&quot;)                 and request.user.member.is_active                 and request.user.member.is_manager             )         )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0423 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0435\u0441\u0442\u044c \u043c\u0438\u043d\u0443\u0441: \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u043c\u0438\u0448\u043d\u043e\u0432 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 2-\u0445, \u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0442\u0438. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0439 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0435\u0440\u043c\u0438\u0448\u043d\u044b \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c\u0441\u044f, \u0442\u043e \u043a\u043e\u0434 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<h3 id=\"pochemu-neobhodimost-v-takih-sostavnyh-permishnah-voobsche-voznikaet\">\u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u0442\u0430\u043a\u0438\u0445 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0445 \u043f\u0435\u0440\u043c\u0438\u0448\u043d\u0430\u0445 \u0432\u043e\u043e\u0431\u0449\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442<\/h3>\n<p>  <\/p>\n<p>\u0412 django-rest-framework \u043f\u0435\u0440\u043c\u0438\u0448\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0432\u044c\u044e, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0435 permissions_class, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 AND. <\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># views.py class TaskView(APIView):     ...     permission_classes = (CompanyManagerOnly, EmployeeOnly)     ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u044c\u044e \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438, \u0438\u043c\u0435\u044e\u0449\u0438\u0435 \u043e\u0431\u0430 \u043f\u0440\u043e\u0444\u0438\u043b\u044f.<\/p>\n<p>  <\/p>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u0444\u043e\u043a\u0443\u0441\u044b \u0441 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u043c\u0438\u0448\u043d\u0430\u043c\u0438 <code>EmployeeAndCompanyManagerOnly<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u0435\u0440\u043c\u0438\u0448\u043d \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># views.py class TaskView(APIView):     ...     permission_classes = (EmployeeAndCompanyManagerOnly,)     ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 \u0432\u0435\u0440\u0441\u0438\u0438 3.9 \u0432 drf \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0437 \u043f\u0435\u0440\u043c\u0438\u0448\u043d\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># views.py class TaskView(APIView):     ...     permission_classes = ((CompanyManagerOnly|EmployeeOnly),)     ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0438 \u0441\u0438\u043c\u043f\u0430\u0442\u0438\u0447\u043d\u044b\u0439, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u0447\u0435\u043c \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u043a\u0443\u0447\u0443 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0445 \u043f\u0435\u0440\u043c\u0438\u0448\u043d \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0432\u0435\u0440\u0441\u0438\u044e drf 3.11, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043d\u043e\u0432\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c. \u042d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0432 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u044f \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<p>  <\/p>\n<p>P.S. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0443 \u043c\u0435\u043d\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u0435\u0449\u0435 \u043f\u0435\u0440\u043c\u0438\u0448\u043d\u044b \u0434\u043b\u044f CompanyOwnerOnly \u0438 CompanyMemberOnly, \u0438 \u043c\u043d\u0435 \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0447\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e.<\/p>\n<p>  <\/p>\n<h1 id=\"dostup-k-odnim-i-tem-zhe-resursam-ot-raznyh-profiley\">\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c \u043e\u0442 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439<\/h1>\n<p>  <\/p>\n<p>\u041c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u0438 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430. <\/p>\n<p>  <\/p>\n<h3 id=\"nemnogo-o-tom-kak-ya-organizuyu-api\">\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u044e \u0430\u043f\u0438<\/h3>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430-\u0442\u043e \u0434\u0430\u0432\u043d\u043e, \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 (<em>\u041a\u0430\u043a \u0436\u0435 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c REST API? \u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u0430\u043f\u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c RESTful? \u0414\u0430 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e? \u0414\u043e\u043b\u0436\u043d\u044b \u0436\u0435 \u0431\u044b\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e best practice?<\/em>), \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043c\u043d\u0435\u043d\u0438\u0439 \u043c\u043d\u043e\u0433\u043e, \u0430 \u0447\u0435\u0442\u043a\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b \u043d\u0435\u0442. \u041d\u043e \u0432\u0441\u0435 \u043c\u043d\u0435\u043d\u0438\u044f \u0441\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c: \u043d\u0435 \u0431\u043e\u0439\u0442\u0435\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0432 \u0432\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<p>  <\/p>\n<p>\u0418 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u044f \u0432\u044b\u0432\u0435\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0435\u0437\u0438\u0441\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li><strong>\u041d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0439.<\/strong> \u0412 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0443\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0433\u043e\u0440\u0434\u043e\u0435 \u0437\u0432\u0430\u043d\u0438\u0435 RESTful, \u0430\u043f\u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c, \u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e \u0440\u0430\u0441\u0442\u0438. \u0422\u0430\u043a \u043a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043d\u044b\u0445 \u0433\u043b\u0430\u0433\u043e\u043b\u0430\u043c\u0438 GET POST PUT DELETE, \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0442\u044c. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0447\u0442\u043e-\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0447\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 AuthorBook.<\/li>\n<li><strong>\u041d\u0435 \u0431\u043e\u0439\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c action endpoint&#8217;\u044b.<\/strong> \u0414\u043e\u0431\u0430\u0432\u0438\u0432 \u043d\u0435\u043c\u043d\u043e\u0433\u043e RPC \u0432 \u043d\u0430\u0448 REST, \u043c\u044b \u043f\u043e\u0439\u043c\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u043e \u043d\u0438\u0447\u0443\u0442\u044c \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u043e \u0432 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0435. \u0417\u0430\u0442\u043e \u0436\u0438\u0437\u043d\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0444\u043b\u0430\u0433\u043e\u0432 \u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/li>\n<li><strong>\u041d\u0435 \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0439 action endopoint&#8217;\u0430\u043c\u0438.<\/strong> \u0415\u0441\u043b\u0438 \u0438\u0445 \u0441\u0442\u0430\u043b\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e, \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0432\u043e\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u044b\u0439, \u0438 \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e viewsets \u043e\u0442 drf, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u044f\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u043c REST \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0418 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0431\u0430\u0432\u043b\u044f\u044e \u0435\u0433\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044d\u043a\u0448\u043d\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/82\/_1\/au\/82_1aulha4l2plygfseghepqmfk.png\"\/><\/p>\n<p>  <\/p>\n<h3 id=\"vernemsya-k-nashey-probleme\">\u0412\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435<\/h3>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043e\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0441\u0443\u0440\u0441, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># models.py class Task(models.Model):     ...  # views.py class TaskViewSet(     mixins.CreateModelMixin,     mixins.UpdateModelMixin,     mixins.ListModelMixin,     mixins.RetrieveModelMixin,     viewsets.GenericViewSet, ):     serializer_class = TaskSerializer      def get_permissions(self):         if self.action in [&quot;accept_invite&quot;, &quot;reject_invite&quot;, &quot;employee_me&quot;]:             return (EmployeeOnly(),)          if self.action in [             &quot;accept_employees&quot;,             &quot;reject_employees&quot;,             &quot;create&quot;,             &quot;update&quot;,             &quot;partial_update&quot;,         ]:             return (CompanyManagerOnly(),)          return ((CompanyManagerOnly | EmployeeOnly)(),) # \u0442\u043e\u0436\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u043e \u043e\u0442 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438      ...<\/code><\/pre>\n<p>  <\/p>\n<p>C\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u044d\u043a\u0448\u043d\u043e\u0432 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (&quot;create&quot;, &quot;update&quot;, &quot;partial_update&quot; \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u044d\u043a\u0448\u043d\u043e\u0432 drf), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0430\u043f\u0438 \u043e\u0442 \u0438\u043c\u0435\u043d\u0438 \u0418\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f (\u0434\u043b\u044f \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438):<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g4\/o0\/kz\/g4o0kz_ch6kgahnns9sr4p7svim.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0418 \u0432\u0441\u0435 \u0431\u044b \u0431\u044b\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0435 \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043e\u0431\u0430 \u043f\u0440\u043e\u0444\u0438\u043b\u044f, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0441\u0432\u0430\u0433\u0433\u0435\u0440 \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u0442 \u043d\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/9u\/6z\/h9\/9u6zh9w3s_3mhqzddzpz9ecnfre.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0422\u0443\u0442 \u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043e\u0442 \u0438\u043c\u0435\u043d\u0438 \u043a\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u044f \u0445\u043e\u0447\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447, \u0435\u0441\u043b\u0438 \u0443 \u043c\u0435\u043d\u044f \u0438\u0445 \u0434\u0432\u0430.<\/li>\n<li>\u0418\u043c\u0435\u044f \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u0430\u0434\u0430\u0447\u0435 (\u043c\u043e\u0433\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0435 \u043f\u043e GET \/tasks\/), \u044f \u043c\u043e\u0433\u0443 \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043d\u0435\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043c\u043e\u0435\u0439 \u0440\u043e\u043b\u044c\u044e \u0432 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0430 \u043d\u0435 \u043d\u0430\u043b\u0438\u0447\u0438\u0435\u043c \u0443 \u043c\u0435\u043d\u044f \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0418 \u0440\u0435\u0448\u0438\u0442\u044c \u0438\u0445 \u043d\u0430\u0432\u0441\u043a\u0438\u0434\u043a\u0443 \u043c\u043e\u0436\u043d\u043e 4-\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<ol>\n<li>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 <code>TaskViewSet<\/code> \u0434\u043b\u044f \u0418\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f \u0438 \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0430.<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041f\u043b\u044e\u0441\u044b<\/th>\n<th>\u041c\u0438\u043d\u0443\u0441\u044b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u041a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439, \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 if<\/td>\n<td>\u0421\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0442\u0435\u0442<\/td>\n<\/tr>\n<tr>\n<td>&#8212;<\/td>\n<td>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044c\u044e\u0445 \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0439 (\u0442\u0440\u0443\u0434\u043d\u0435\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c)<\/td>\n<\/tr>\n<tr>\n<td>&#8212;<\/td>\n<td>Employee \u0438 \u0421ompany \u044d\u0442\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043d\u0435 \u043f\u0443\u0442\u044c \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0443, \u0430 \u0440\u043e\u043b\u044c, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0432 \u044d\u0442\u043e\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0435, \u043a\u0430\u043a-\u0442\u043e \u043d\u0435 &quot;\u043f\u043e-\u0440\u0435\u0441\u0442\u043e\u0432\u0441\u043a\u0438&quot; \u043f\u0438\u0445\u0430\u0442\u044c \u0435\u0435 \u0432 url<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0445\u044d\u0434\u0435\u0440 \u0432 \u0440\u0435\u043a\u0432\u0435\u0441\u0442\u0435 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0445\u043e\u0447\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441.<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041f\u043b\u044e\u0441\u044b<\/th>\n<th>\u041c\u0438\u043d\u0443\u0441\u044b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (\u043d\u0438\u0447\u0435\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u0432 \u0443\u0440\u043b\u0430\u0445)<\/td>\n<td>\u0412 \u043b\u043e\u0433\u0430\u0445 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e: \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0433\u0434\u0435-\u0442\u043e \u0443\u043f\u0430\u0434\u0435\u0442, \u0441\u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043e\u0442 \u0438\u043c\u0435\u043d\u0438 \u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<\/tr>\n<tr>\n<td>&#8212;<\/td>\n<td>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (drf_yasg) \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0445\u044d\u0434\u0435\u0440\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0430\u0441\u044c \u0431\u044b \u0432 \u0430\u0434<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c query \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0443\u0440\u043b\u0435.<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041f\u043b\u044e\u0441\u044b<\/th>\n<th>\u041c\u0438\u043d\u0443\u0441\u044b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u0412\u044c\u044e \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u043d\u0430<\/td>\n<td>\u0421\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432\u044c\u044e \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u0441\u044f: \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0435 if else<\/td>\n<\/tr>\n<tr>\n<td>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u043c\u043f\u0430\u0442\u0438\u0447\u043d\u0430\u044f (\u0432\u043a\u0443\u0441\u043e\u0432\u0449\u0438\u043d\u0430)<\/td>\n<td>&#8212;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/li>\n<li>\n<p>HATEOAS (\u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435!)<\/p>\n<p>  <\/p>\n<p>\u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043b\u044e\u0441\u044b-\u043c\u0438\u043d\u0443\u0441\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u0432 \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u044b. \u0427\u0438\u0442\u0430\u043b, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u043e\u0431\u043d\u043e \u0438 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c.<br \/>  \u041d\u043e \u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044c \u043d\u0435 \u043c\u043e\u0433\u0443.<br \/>  \u0422\u0430\u043a \u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435 \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u21161.<\/p>\n<p>  <\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u042f \u0432\u044b\u0431\u0440\u0430\u043b <strong>\u0442\u0440\u0435\u0442\u044c\u0435<\/strong> \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043d\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043c\u0438\u043d\u0443\u0441\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e \u0435\u0433\u043e \u043a \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0442\u0435\u0445 \u044d\u043a\u0448\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u044d\u0442\u043e\u0442 query \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># serializers.py class ModeSerializer(serializers.Serializer):     mode = serializers.ChoiceField(MODE)  # views.py @swagger_auto_schema(query_serializer=ModeSerializer) def list(self, request, *args, **kwargs):     return super().list(request, *args, **kwargs)  @swagger_auto_schema(query_serializer=ModeSerializer) def retrieve(self, request, pk, *args, **kwargs):     return super().retrieve(request, *args, **kwargs)<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vw\/ps\/ub\/vwpsubpptp-ulf_-8lar3edjkf0.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0438\u043c\u043f\u0430\u0442\u0438\u0447\u043d\u043e \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0448\u0442\u0440\u0438\u0445\u043e\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c queryset \u0432\u043e \u0432\u044c\u044e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e mode.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># views.py def get_queryset(self):     if getattr(self, &quot;swagger_fake_view&quot;, False):         return Task.objects.none()      mode = self.request.query_params.get(&quot;mode&quot;)      if mode == MODE.COMPANY:         return Task.objects.filter(author=self.request.user).order_by(&quot;-created_at&quot;)     elif mode == MODE.EMPLOYEE:         # \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0432\u043e\u0437\u043d\u044f \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0435\u0439, \u043d\u043e \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0447\u0442\u043e \u043c\u044b          # \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 queryset!         tasks = set(             taskemployee.task.id             for taskemployee in self.request.user.employee.taskemployee_set.exclude(                 invite_status=SUGGEST_STATUS.REJECT             )             if taskemployee.task.status             in [                 TASK_STATUS.IN_WORK,                 TASK_STATUS.DONE,             ]         )         return Task.objects.filter(id__in=tasks).order_by(&quot;-created_at&quot;)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u21161, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0435\u043c, \u043e\u0442 \u043a\u0430\u043a\u043e\u0439 \u0440\u043e\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c, \u043a\u0430\u043a \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0418\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c, \u043d\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a (\u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043d\u0435 \u0435\u0435 \u0430\u0432\u0442\u043e\u0440, \u0445\u043e\u0442\u044c \u0443 \u043d\u0430\u0441 \u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0430).<\/p>\n<p>  <\/p>\n<p>\u0418 \u0442\u0443\u0442 \u043c\u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u0442\u043e, \u043a\u0430\u043a \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d \u043c\u0435\u0442\u043e\u0434 self.get_object() \u0432 drf view.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># rest_framework.generics.GenericAPIView class GenericAPIView(views.APIView):     ...      def get_object(self):         ...          queryset = self.filter_queryset(self.get_queryset())          ...          obj = get_object_or_404(queryset, **filter_kwargs)          # May raise a permission denied         self.check_object_permissions(self.request, obj)          return obj<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043d \u0438\u0449\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 <code>queryset = self.filter_queryset(self.get_queryset())<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0443 \u0432\u044c\u044e \u043d\u0435\u0442. <\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043a\u043e\u0434\u0430 \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u0438 \u0432\u0442\u043e\u0440\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># views.py def get_queryset(self):     if getattr(self, &quot;swagger_fake_view&quot;, False):         return Task.objects.none()      mode = self.request.query_params.get(&quot;mode&quot;)      if mode == MODE.COMPANY or self.action in [         &quot;create&quot;,         &quot;update&quot;,         &quot;partial_update&quot;,         &quot;accept_employees&quot;,         &quot;reject_employees&quot;,     ]:         ...     elif mode == MODE.EMPLOYEE or self.action in [         &quot;accept_invite&quot;,         &quot;reject_invite&quot;,     ]:         ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0435\u043d\u0430: \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0441\u044c, \u043c\u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430 404 NotFound, \u0442.\u043a. queryset \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e \u0432\u0435\u0442\u043a\u0435 <code>MODE.COMPANY<\/code> \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0440\u0435\u0441\u0443\u0440\u0441.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043d\u0430\u0432\u0435\u0441\u0442\u0438 \u043a\u0440\u0430\u0441\u043e\u0442\u0443: \u043c\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u0442\u043e, \u0447\u0442\u043e \u0432 if \u043c\u044b \u043c\u0435\u0448\u0430\u0435\u043c \u0438 mode \u0438\u0437 \u0443\u0440\u043b\u0430, \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u043e \u044d\u043a\u0448\u043d\u0430\u043c. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043a\u0448\u043d\u0430 \u043d\u0430\u0434\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0435\u0433\u043e \u0437\u0434\u0435\u0441\u044c \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0441\u0442\u0430\u043b\u043e \u043b\u0443\u0447\u0448\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># views.py class TaskViewSet(     mixins.CreateModelMixin,     mixins.UpdateModelMixin,     mixins.ListModelMixin,     mixins.RetrieveModelMixin,     viewsets.GenericViewSet, ):     ...      action_default_mode = {         &quot;create&quot;: MODE.COMPANY,         &quot;update&quot;: MODE.COMPANY,         &quot;partial_update&quot;: MODE.COMPANY,         &quot;accept_invite&quot;: MODE.EMPLOYEE,         &quot;reject_invite&quot;: MODE.EMPLOYEE,         &quot;employee_me&quot;: MODE.EMPLOYEE,     }      def get_queryset(self):         if getattr(self, &quot;swagger_fake_view&quot;, False):             return Task.objects.none()          mode = self.request.query_params.get(&quot;mode&quot;) or self.action_default_mode.get(             self.action         )          assert mode, (             &quot;You need to add required query param in your urls &quot;             &quot;or set an action default mode in self.action_default_mode map&quot;             f&quot; for action `{self.action}`&quot;         )          if mode == MODE.COMPANY:             ...         elif mode == MODE.EMPLOYEE:             ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u043e\u0442 \u0447\u0435\u0433\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a \u044d\u0442\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u044d\u043a\u0448\u043d\u0430 \u044f \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043a\u0440\u043e\u043b\u0438\u0442\u044c \u0434\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0438 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0442\u0443\u0434\u0430 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 \u043c\u043e\u0434. \u041f\u043e-\u043f\u0438\u0442\u043e\u043d\u044f\u0447\u0438 \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0438 \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u044d\u043a\u0448\u043d \u0441\u0440\u0430\u0437\u0443, \u043d\u043e \u044d\u0442\u0443 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u044f \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u043d\u0430 \u043f\u043e\u0442\u043e\u043c.<\/p>\n<p>  <\/p>\n<h1 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044f \u043d\u0430\u0431\u0438\u0440\u0430\u043b \u044d\u0442\u043e\u0442 \u0442\u0435\u043a\u0441\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0448\u0430\u0433.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442, \u0438 \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0443\u0434\u0430\u0447\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u0435\u0440\u043c\u0438\u0448\u043d\u0430\u043c\u0438 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0445\u0430\u0431\u0440 \u044f \u0440\u0435\u0448\u0438\u043b \u0437\u0430\u043f\u043e\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u0442.\u043a. \u043f\u043e\u043a\u0430 \u0440\u0435\u0448\u0430\u043b \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0434\u043e\u043b\u0433\u043e \u0438\u0441\u043a\u0430\u043b \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435, \u043d\u043e \u043d\u0430\u0448\u0435\u043b \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043d\u0430 \u0442\u0435\u043c\u0443 &quot;\u043e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u2014 \u043c\u043d\u043e\u0433\u043e \u0440\u043e\u043b\u0435\u0439&quot;.<\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0447\u0435\u0442\u0441\u044f \u0443\u0437\u043d\u0430\u0442\u044c \u043d\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u043b \u043b\u0438 \u044f \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434 \u0432 \u0441\u0442\u0435\u043a\u0435 Django, drf. \u0410 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u0435\u0439\u0441, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u044d\u0442\u043e \u0432 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043b\u0430\u0433\u0438\u043d\u0447\u0438\u043a \u0434\u043b\u044f \u0434\u0436\u0430\u043d\u0433\u043e.<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e!<\/p>\n<\/div>\n<p> \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\/505156\/\"> https:\/\/habr.com\/ru\/post\/505156\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/505156\/\">\n<h1 id=\"problema\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h1>\n<p>  <\/p>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 API \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0432\u0435\u0431-\u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u044f \u0432\u0437\u044f\u043b \u0441\u0432\u043e\u0439 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u0441\u0442\u0435\u043a:<\/p>\n<p>  <\/p>\n<ul>\n<li>Django<\/li>\n<li>django-rest-framework<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u043e \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0441\u0442\u043e\u044f\u043b\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u0440\u0438\u0432\u044b\u0447\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u0443 User \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 (\u0418\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c, \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a). \u0418 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 \u0434\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u043b\u043d\u043e\u043c\u043e\u0447\u0438\u044f \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043e\u0434\u043d\u0438\u043c\u0438 \u0438 \u0442\u0435\u043c\u0438 \u0436\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043d\u0435 \u0437\u0430\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u043e\u043b\u0438, \u0447\u0442\u043e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0432\u0438\u0434\u0443 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c: \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 email \u0438\u043b\u0438 \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043e\u043f\u0438\u0448\u0435\u043c \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0438\u0435 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u2013 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439.<\/li>\n<li>\u041a\u0430\u043a \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439.<\/li>\n<li>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0434\u043d\u0438\u043c \u0442\u0435\u043c \u0436\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c \u043e\u0442 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0441\u0432\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043b\u043e\u0436\u0438\u043b\u0441\u044f \u0438\u0437 \u0443\u0436\u0435 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0432\u044b\u0447\u0435\u043a \u043f\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 Django-\u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e\u0435 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/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-304772","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304772","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=304772"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304772\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=304772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=304772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=304772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}