{"id":324912,"date":"2021-06-15T09:00:14","date_gmt":"2021-06-15T09:00:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324912"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324912","title":{"rendered":"Django Rest Framework \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445: \u0441\u043e\u0437\u0434\u0430\u0451\u043c API \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (\u0447\u0430\u0441\u0442\u044c 2)"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/company\/yandex_praktikum\/blog\/561696\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u043c\u044b \u0432 \u043e\u0431\u0449\u0438\u0445 \u0447\u0435\u0440\u0442\u0430\u0445 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d REST API \u043d\u0430 DRF \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435. \u0415\u0434\u0432\u0430 \u043b\u0438 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u044d\u0442\u0430\u043f \u2014 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f. \u0412\u043e\u043e\u0440\u0443\u0436\u0438\u0432\u0448\u0438\u0441\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u044d\u0442\u043e\u0442 \u044d\u0442\u0430\u043f \u2014 \u043e\u0442 \u043f\u0440\u0438\u0435\u043c\u0430 \u043d\u0430\u0431\u043e\u0440\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043e \u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439.<\/p>\n<p>  <\/p>\n<p><strong>\u0412\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442:<\/strong> \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043e\u0442\u0434\u0430\u0451\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0411\u0414) \u0441\u0430\u0439\u0442\u0430. \u041e \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c, \u043a\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0438\u0437\u0432\u043d\u0435 \u0438 \u0438\u0445 \u043d\u0430\u0434\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0411\u0414, \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u0443\u0447\u0435\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d <a href=\"https:\/\/github.com\/stasyao\/drf_guide_part_1\">\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430 \u0413\u0438\u0442\u0445\u0430\u0431\u0435<\/a>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dn\/kf\/sf\/dnkfsf4d8gmnnxmf1qr2x6j_r6y.png\"><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"kak-sozdayotsya-serialayzer-rabotayuschiy-na-chtenie\">\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># capitals\/views.py          serializer_for_queryset = CapitalSerializer(             instance=queryset,  # \u041f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0438\u0441\u0435\u0439             many=True # \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u043e\u0434\u0430\u0451\u0442\u0441\u044f \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0438\u0441\u0435\u0439         )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <code>many=True<\/code> \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>many_init<\/code> \u043a\u043b\u0430\u0441\u0441\u0430 <code>BaseSerializer<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class BaseSerializer(Field):        \u2026     def __new__(cls, *args, **kwargs):         if kwargs.pop('many', False):             return cls.many_init(*args, **kwargs)         return super().__new__(cls, *args, **kwargs)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043c\u0435\u0442\u043e\u0434\u0435 <code>many_init<\/code>:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u043e\u043d \u043c\u0435\u043d\u044f\u0435\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441. \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043d\u0435 <code>CapitalSerializer<\/code>, \u0430 \u043a\u043b\u0430\u0441\u0441 DRF \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 <code>restframework.serializers.ListSerializer<\/code>.<\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u043d\u0430\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c child. \u0412 \u043d\u0435\u0433\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440 \u2014 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 CapitalSerializer.<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"python\"> @classmethod     def many_init(cls, *args, **kwargs):         ...         child_serializer = cls(*args, **kwargs)         list_kwargs = {             'child': child_serializer,         }       ...         meta = getattr(cls, 'Meta', None)         list_serializer_class = getattr(meta, 'list_serializer_class',                            ListSerializer)         return list_serializer_class(*args, **list_kwargs) <\/code><\/pre>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430<\/th>\n<th>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/th>\n<th>\u041a \u043a\u0430\u043a\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>serializer_for_queryset<\/code><\/td>\n<td>\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/td>\n<td><strong>ListSerializer<\/strong> \u2014 \u043a\u043b\u0430\u0441\u0441 \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>restframework.serializers<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>serializer_for_queryset.child<\/code><\/td>\n<td>\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043d\u0430\u0431\u043e\u0440\u0435<\/td>\n<td><strong>CapitalSerializer<\/strong> \u2014 \u043d\u0430\u0448 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Serializer<\/code> \u043c\u043e\u0434\u0443\u043b\u044f <code>restframework.serializers<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e <code>many=True<\/code> \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 instance (\u0438\u043d\u0441\u0442\u0430\u043d\u0441). \u0412 \u043d\u0451\u043c \u2014 \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<p><strong>\u0412\u0430\u0436\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0442\u0430\u0442\u044c\u0441\u044f \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0435 \u0432 \u0446\u0435\u043b\u043e\u043c, \u0430 \u043a\u043e\u0433\u0434\u0430 \u2014 \u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0435, \u0434\u0430\u043b\u0435\u0435 \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u00ab\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u00bb (<a href=\"https:\/\/github.com\/stasyao\/drf_guide_part_1\/blob\/master\/capitals\/views.py#L14\">\u0432 \u043a\u043e\u0434\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/a> \u044d\u0442\u043e <code>serializer_for_queryset<\/code>) \u0438 \u00ab\u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u00bb (\u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>child<\/code> \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430).<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u043c\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0435\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 <code>data<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">return Response(serializer_for_queryset.data)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"chto-pod-kapotom-atributa-data-osnovnogo-serialayzera\">\u0427\u0442\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 <code>data<\/code> \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430<\/h2>\n<p>  <\/p>\n<p><strong>\u0412\u0430\u0436\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>data<\/code> \u0435\u0441\u0442\u044c \u0438 \u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e, \u0438 \u0443 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c: \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e (<code>serializer_for_queryset<\/code>) \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043a\u043b\u0430\u0441\u0441\u0443 <code>ListSerializer<\/code>.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/71e6c30034a1dd35a39ca74f86c371713e762c79\/rest_framework\/serializers.py#L743\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a> \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 <code>data<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class ListSerializer(BaseSerializer):     ...     @property     def data(self):         ret = super().data         return ReturnList(ret, serializer=self)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>data<\/code> \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e <code>BaseSerializer<\/code>. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class BaseSerializer(Field):        \u2026      @property     def data(self):     ...          if not hasattr(self, '_data'):             if self.instance is not None and not getattr(self, '_errors', None):                 self._data = self.to_representation(self.instance)             ...         return self._data<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0449\u0451 \u043d\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b (\u043d\u0435\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 <code>_data<\/code>), \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f (\u043d\u0435\u0442 <code>_errors<\/code>), \u043d\u043e \u0435\u0441\u0442\u044c \u0438\u043d\u0441\u0442\u0430\u043d\u0441 (\u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438), \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>to_representation<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"kak-rabotaet-metod-to_represantation-osnovnogo-serialayzera\">\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>to_represantation<\/code> \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430<\/h2>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u043a\u043b\u0430\u0441\u0441 <code>ListSerializer<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class ListSerializer(BaseSerializer):        \u2026     def to_representation(self, data):         &quot;&quot;&quot;         List of object instances -&gt; List of dicts of primitive datatypes.         &quot;&quot;&quot;         iterable = data.all() if isinstance(data, models.Manager) else data         return [             self.child.to_representation(item) for item in iterable         ]<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/3875d3284e73ed4d8e36c07d9b70c1b22c9d5998\/rest_framework\/serializers.py#L655\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043d\u0435\u0445\u0438\u0442\u0440\u044b\u0439:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 (\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 <code>instance<\/code>) \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0446\u0438\u043a\u043b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>data<\/code>;<\/li>\n<li>\u0432 \u0445\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0446\u0438\u043a\u043b\u0430 \u043a\u0430\u0436\u0434\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>to_representation<\/code> \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 (<code>self.child.to_representation(item)<\/code>). \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u00ab\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u2014 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u00bb.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0427\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u043e\u0434\u043d\u0443 \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0411\u0414, \u0430 \u043d\u0430\u0431\u043e\u0440, \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c <code>many=True<\/code>.<\/li>\n<li>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043c\u0430\u0442\u0440\u0451\u0448\u043a\u0443 \u2014 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440 \u0441 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u0432\u043d\u0443\u0442\u0440\u0438.<\/li>\n<li>\u0417\u0430\u0434\u0430\u0447\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 (\u043e\u043d \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043a\u043b\u0430\u0441\u0441\u0443 <code>ListSerializer<\/code>) \u2014 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0446\u0438\u043a\u043b, \u0432 \u0445\u043e\u0434\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442 \u0435\u0435 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c.<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"kak-rabotaet-metod-to_representation-dochernego-serialayzera\">\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>to_representation<\/code> \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430<\/h2>\n<p>  <\/p>\n<p>\u0414\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440 \u2014 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>CapitalSerializer<\/code> \u2014 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442 <code>restframework.serializers.Serializer<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class Serializer(BaseSerializer, metaclass=SerializerMetaclass): \u2026     def to_representation(self, instance):         &quot;&quot;&quot;         Object instance -&gt; Dict of primitive datatypes.         &quot;&quot;&quot;         ret = OrderedDict()         fields = self._readable_fields          for field in fields:             try:                 attribute = field.get_attribute(instance)             except SkipField:                 continue             check_for_none = attribute.pk if isinstance(attribute, PKOnlyObject)       else attribute             if check_for_none is None:                 ret[field.field_name] = None             else:                 ret[field.field_name] = field.to_representation(attribute)          return ret<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/3875d3284e73ed4d8e36c07d9b70c1b22c9d5998\/rest_framework\/serializers.py#L493\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0439\u0434\u0451\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u043e\u0439 <code>OrderedDict<\/code>, \u0434\u0430\u043b\u0435\u0435 \u0438\u0434\u0451\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 <code>_readable_fields<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u043a\u0443\u0434\u0430 \u0431\u0435\u0440\u0451\u0442\u0441\u044f <code>_readable_fields<\/code>? \u0421\u043c\u043e\u0442\u0440\u0438\u043c <a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/3875d3284e73ed4d8e36c07d9b70c1b22c9d5998\/rest_framework\/serializers.py#L359\">\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class Serializer(BaseSerializer, metaclass=SerializerMetaclass):        \u2026     @property     def _readable_fields(self):         for field in self.fields.values():             if not field.write_only:                 yield field<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c <code>_readable_fields<\/code> \u2014 \u044d\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442a <code>write_only<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>True<\/code>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d <code>False<\/code>. \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c <code>True<\/code>, \u043f\u043e\u043b\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438, \u043d\u043e \u0431\u0443\u0434\u0435\u0442 <a href=\"https:\/\/ilyachch.gitbook.io\/django-rest-framework-russian-documentation\/overview\/navigaciya-po-api\/fields#write_only\">\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0435\u0451 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0435 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435) \u2014 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 <code>write only<\/code> \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 <code>_readable_fields<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0442\u0440\u0438 \u043f\u043e\u043b\u044f \u2014 <code>capital_city<\/code>, <code>capital_population<\/code>, <code>author<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0427\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0434 <code>to_representation<\/code> \u0434\u0430\u043b\u0435\u0435: \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 <code>_readable_fields<\/code> \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0446\u0438\u043a\u043b, \u0438 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>get_attribute<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043e\u0434 <code>to_representation<\/code> \u0434\u0430\u043b\u044c\u0448\u0435, \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0443 \u043f\u043e\u043b\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u2014 <code>to_representation<\/code>. \u042d\u0442\u043e \u043d\u0435 \u043e\u043f\u0435\u0447\u0430\u0442\u043a\u0430: \u043c\u0435\u0442\u043e\u0434 <code>to_representation<\/code> \u043f\u043e\u0434 \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c, \u043d\u043e \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439: <\/p>\n<p>  <\/p>\n<ul>\n<li>\u0435\u0441\u0442\u044c \u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>ListSerializer<\/code>; <\/li>\n<li>\u0443 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>Serializer<\/code>; <\/li>\n<li>\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044f.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b <code>get_attribute<\/code> \u0438 <code>to_representation<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0441\u043a\u043e\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"kak-zapis-iz-modeli-obrabatyvaetsya-metodami-poley-serialayzera\">\u041a\u0430\u043a \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043f\u043e\u043b\u0435\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430<\/h2>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>get_attribute<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u043c (instance). \u0412\u0430\u0436\u043d\u043e \u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0441 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430. \u0418\u043d\u0441\u0442\u0430\u043d\u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438. \u0418\u043d\u0441\u0442\u0430\u043d\u0441 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u2014 \u043a\u0430\u0436\u0434\u0430\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c. <\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c <a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/3875d3284e73ed4d8e36c07d9b70c1b22c9d5998\/rest_framework\/serializers.py#L664\">\u0441\u0442\u0440\u043e\u043a\u0443<\/a> \u0438\u0437 \u043a\u043e\u0434\u0430 <code>to_representation<\/code> \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">[self.child.to_representation(item) for item in iterable]<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 item (\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430) \u0438 \u0435\u0441\u0442\u044c \u0438\u043d\u0441\u0442\u0430\u043d\u0441, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>get_attribute<\/code> \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class Field:        ...     def get_attribute(self, instance):         try:             return get_attribute(instance, self.source_attrs)       ...<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/fields.py#L451\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/p>\n<p>  <\/p>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>get_attribute<\/code>, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u0441\u0435\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f <code>rest_framework.fields<\/code>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043f\u043e\u043b\u044f <code>source_attrs<\/code>. \u042d\u0442\u043e <a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/3875d3284e73ed4d8e36c07d9b70c1b22c9d5998\/rest_framework\/fields.py#L401\">\u0441\u043f\u0438\u0441\u043e\u043a<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>split<\/code> (\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u2014 \u0442\u043e\u0447\u043a\u0430) \u043a \u0441\u0442\u0440\u043e\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 <code>source<\/code> \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u043e\u043b\u044f. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0438, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <code>source<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u0437\u044f\u0442\u043e <a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/3875d3284e73ed4d8e36c07d9b70c1b22c9d5998\/rest_framework\/fields.py#L393\">\u0438\u043c\u044f \u043f\u043e\u043b\u044f<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#str.split\"><code>split<\/code><\/a>, \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0438 source \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u043b\u0430\u0441\u044c \u0442\u043e\u0447\u0435\u0447\u043d\u0430\u044f \u043d\u043e\u0442\u0430\u0446\u0438\u044f, \u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class CapitalSerializer(serializers.Serializer):     capital_city = serializers.CharField(max_length=200)     capital_population = serializers.IntegerField()     author = serializers.CharField(source='author.username', max_length=200)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041f\u043e\u043b\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430<\/th>\n<th>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 source \u043f\u043e\u043b\u044f<\/th>\n<th>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 source_attrs<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>capital_city<\/td>\n<td>&#8216;capital_city&#8217;<\/td>\n<td>[&#8216;capital_city&#8217;]<\/td>\n<\/tr>\n<tr>\n<td>capital_population<\/td>\n<td>&#8216;capital_population&#8217;<\/td>\n<td>[&#8216;capital_population&#8217;]<\/td>\n<\/tr>\n<tr>\n<td>author<\/td>\n<td>&#8216;author.username&#8217;<\/td>\n<td>[&#8216;author&#8217;, &#8216;username&#8217;]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u044b \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438, \u0441\u043f\u0438\u0441\u043e\u043a <code>source_attrs<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 attrs \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/bc075212cb05a52a2b2b2b4c909cfbd03c7ebd8e\/rest_framework\/fields.py#L85\"><code>get_attribute rest_framework.fields<\/code><\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def get_attribute(instance, attrs):     for attr in attrs:         try:             if isinstance(instance, Mapping):                 instance = instance[attr]             else:                 instance = getattr(instance, attr)         ...     return instance<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0435\u0439 <code>capital_city<\/code> \u0438 <code>capital_population<\/code> \u0446\u0438\u043a\u043b <code>for attr in attrs<\/code> \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>instance = getattr(instance, attr)<\/code>. \u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f Python-\u0444\u0443\u043d\u043a\u0446\u0438\u044f <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#getattr\"><code>getattr<\/code><\/a> \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 (instance) \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 (<code>attr<\/code>) \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<br \/>  \u041f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">instance = getattr(\u0437\u0430\u043f\u0438\u0441\u044c_\u043e_\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439_\u0441\u0442\u043e\u043b\u0438\u0446\u0435, 'capital_city')<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 <code>author.username<\/code> \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. \u0414\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 <code>username<\/code> DRF \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 Capital. \u0418\u0437 <code>source_attrs<\/code> \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>author<\/code>, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0438\u043c\u0451\u043d\u043d\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u043c. <code>author<\/code> \u2014 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 User, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 Capital \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447.<\/li>\n<li>\u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0437 <code>source_attrs<\/code> \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>username<\/code>. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 <code>username<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u0437\u044f\u0442\u043e \u0443\u0436\u0435 \u043e\u0442 \u043d\u043e\u0432\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u2014 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>author<\/code>. \u0422\u0430\u043a \u043c\u044b \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0430\u0432\u0442\u043e\u0440\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0418\u0437\u0432\u043b\u0435\u0447\u0451\u043d\u043d\u044b\u0435 \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c <code>ret<\/code>, \u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0441 \u043d\u0438\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>to_representation<\/code> \u043f\u043e\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">ret[field.field_name] = field.to_representation(attribute)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <code>to_representation<\/code> \u2014 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0437\u0432\u043b\u0435\u0447\u0451\u043d\u043d\u044b\u0435 \u0438\u0437 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043a\u043b\u0430\u0441\u0441\u0443 <a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/fields.py#L810\"><code>CharField<\/code><\/a>, \u0442\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0451\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043a \u0441\u0442\u0440\u043e\u043a\u0435, \u0430 \u0435\u0441\u043b\u0438 <a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/bc075212cb05a52a2b2b2b4c909cfbd03c7ebd8e\/rest_framework\/fields.py#L962\"><code>IntegerField<\/code><\/a> \u2014 \u043a \u0446\u0435\u043b\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 <code>to_representation<\/code> \u043f\u043e \u0441\u0443\u0442\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0430\u0441\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0437 \u043f\u043e\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 <code>capital_city<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430. \u041c\u0435\u0442\u043e\u0434 <code>to_representation<\/code> \u043f\u043e\u043b\u044f <code>CharField<\/code> \u043a \u0438\u0437\u0432\u043b\u0435\u0447\u0451\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 <code>str<\/code>. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442. \u041d\u043e \u0435\u0441\u043b\u0438 \u0431\u044b \u0438\u0437 \u043f\u043e\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 <code>IntegerField<\/code> \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u043b\u0438\u0441\u044c \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u043b\u044e \u043a\u043b\u0430\u0441\u0441\u0430 <code>CharField<\/code>, \u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u043e\u043d\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u043b\u0438\u0441\u044c \u0431\u044b \u0432 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430, \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>get_attribute<\/code>, \u0438 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>to_representation<\/code>, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0432\u0448\u0438\u0435 \u043d\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0435. <a href=\"https:\/\/ilyachch.gitbook.io\/django-rest-framework-russian-documentation\/overview\/navigaciya-po-api\/fields#primery\">\u041f\u0440\u0438\u043c\u0435\u0440\u044b<\/a> \u0435\u0441\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u2014 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b <code>ColorField<\/code> \u0438 <code>ClassNameField<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"summiruem-vsyo-chto-uznali\">\u0421\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0451, \u0447\u0442\u043e \u0443\u0437\u043d\u0430\u043b\u0438<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 Django-\u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0435 <code>data<\/code> \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430. \u041f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u044d\u0442\u043e\u043c\u0443 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0438\u0437-\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u0430 DRF (\u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c):<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041c\u0435\u0442\u043e\u0434, \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/th>\n<th>\u041a\u043b\u0430\u0441\u0441, \u043c\u043e\u0434\u0443\u043b\u044c<\/th>\n<th>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/61e7a993bd0702d30e3049179000bc7c5f284781\/rest_framework\/serializers.py#L233\"><code>data<\/code><\/a><\/td>\n<td><code>serializes.BaseSerializer<\/code><\/td>\n<td>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>to_representation<\/code> \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/61e7a993bd0702d30e3049179000bc7c5f284781\/rest_framework\/serializers.py#L655\"><code>to_representation<\/code><\/a><\/td>\n<td><code>serializers.ListSerializer<\/code><\/td>\n<td>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0446\u0438\u043a\u043b, \u0432 \u0445\u043e\u0434\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>to_representation<\/code> \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/61e7a993bd0702d30e3049179000bc7c5f284781\/rest_framework\/serializers.py#L493\"><code>to_representation<\/code><\/a><\/td>\n<td><code>serializers.Serializer<\/code><\/td>\n<td>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u043f\u043e\u043a\u0430 \u043e\u043d \u043f\u0443\u0441\u0442\u043e\u0439. \u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0446\u0438\u043a\u043b \u043f\u043e \u0432\u0441\u0435\u043c \u043f\u043e\u043b\u044f\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e <code>write_only=True<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/61e7a993bd0702d30e3049179000bc7c5f284781\/rest_framework\/fields.py#L85\"><code>get_attribute<\/code><\/a><\/td>\n<td><code>fields<\/code> (\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c <a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/61e7a993bd0702d30e3049179000bc7c5f284781\/rest_framework\/fields.py#L451\"><code>get_attribute<\/code><\/a> \u043a\u043b\u0430\u0441\u0441\u0430 <code>fields.Field<\/code>)<\/td>\n<td>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0442\u044b\u043a\u0443\u0435\u0442 \u043f\u043e\u043b\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u0441 \u043f\u043e\u043b\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u0411\u0414. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u0434\u0435\u0442 \u043f\u043e\u0438\u0441\u043a \u043f\u043e\u043b\u044f, \u0447\u044c\u0451 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430. \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>source<\/code>, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430. \u0418\u0437 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u0442\u0435\u043a\u0441\u0442, \u0447\u0438\u0441\u043b\u0430 \u0438 \u0442.\u0434.<\/td>\n<\/tr>\n<tr>\n<td><code>to_representation<\/code><\/td>\n<td><code>fields.\u041a\u043b\u0430\u0441\u0441\u041f\u043e\u043b\u044f\u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e\u0422\u0438\u043f\u0430<\/code><\/td>\n<td>\u0418\u0437\u0432\u043b\u0435\u0447\u0451\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043b\u043e\u0433\u0438\u043a\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430. \u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044f restframework \u043e\u043d\u0430 \u0441\u0432\u043e\u044f. \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u043b\u044f \u0438 \u043d\u0430\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 <code>to_representation<\/code> \u043b\u044e\u0431\u043e\u0439 \u043d\u0443\u0436\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0437\u0430\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043f\u0430\u0440\u0430 \u00ab\u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043a\u043b\u044e\u0447 \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430;<\/li>\n<li>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u0434\u0430\u043d\u043d\u044b\u0435, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>to_representation<\/code> \u043f\u043e\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0418\u0442\u043e\u0433: \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 <code>OrderedDict<\/code> \u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435, \u0440\u0430\u0432\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<hr>\n<p>  <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0430 \u0434\u0430\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c DRF \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0411\u0414. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0445 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u2014 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435.<\/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\/company\/yandex_praktikum\/blog\/562050\/\"> https:\/\/habr.com\/ru\/company\/yandex_praktikum\/blog\/562050\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/company\/yandex_praktikum\/blog\/561696\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u043c\u044b \u0432 \u043e\u0431\u0449\u0438\u0445 \u0447\u0435\u0440\u0442\u0430\u0445 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d REST API \u043d\u0430 DRF \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435. \u0415\u0434\u0432\u0430 \u043b\u0438 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u044d\u0442\u0430\u043f \u2014 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f. \u0412\u043e\u043e\u0440\u0443\u0436\u0438\u0432\u0448\u0438\u0441\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u044d\u0442\u043e\u0442 \u044d\u0442\u0430\u043f \u2014 \u043e\u0442 \u043f\u0440\u0438\u0435\u043c\u0430 \u043d\u0430\u0431\u043e\u0440\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043e \u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439.<\/p>\n<p>  <\/p>\n<p><strong>\u0412\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442:<\/strong> \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043e\u0442\u0434\u0430\u0451\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0411\u0414) \u0441\u0430\u0439\u0442\u0430. \u041e \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c, \u043a\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0438\u0437\u0432\u043d\u0435 \u0438 \u0438\u0445 \u043d\u0430\u0434\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0411\u0414, \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u0443\u0447\u0435\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d <a href=\"https:\/\/github.com\/stasyao\/drf_guide_part_1\">\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430 \u0413\u0438\u0442\u0445\u0430\u0431\u0435<\/a>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dn\/kf\/sf\/dnkfsf4d8gmnnxmf1qr2x6j_r6y.png\"><\/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-324912","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324912","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=324912"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324912\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}