{"id":262568,"date":"2015-07-29T20:10:02","date_gmt":"2015-07-29T16:10:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=262568"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=262568","title":{"rendered":"Django ORM. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0430\u0445\u0430\u0440\u043a\u0443"},"content":{"rendered":"<p>     \t<img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/0f0\/925\/186\/0f092518650f41a38ae9f8a83f01206d.jpg\"\/><br \/>  \u0424\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Django, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0434\u043b\u044f \u044f\u0437\u044b\u043a\u0430 Python. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0440\u0438 \u0432\u0441\u0435\u0439 \u0435\u0433\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438, \u0447\u0430\u0441\u0442\u043e \u043a\u0440\u0438\u0442\u0438\u043a\u0443\u044e\u0442 \u0435\u0433\u043e ORM \u2014 \u0430 \u0438\u043c\u0435\u043d\u043d\u043e lookup \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0442\u0430\u043a\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d \u2014 \u043e\u043d \u043b\u0435\u0433\u043e\u043a \u0432 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c, \u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u043f\u0440\u043e\u0441\u0442, \u043a\u0430\u043a \u0448\u0432\u0430\u0431\u0440\u0430. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043f\u0440\u044f\u043c\u043e \u0438\u0437\u044f\u0449\u0435\u0441\u0442\u0432\u0430. \u041d\u043e \u043a\u0440\u0430\u0441\u043e\u0442\u0430 \u2014 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0415\u0441\u043b\u0438 \u0437\u0430\u0438\u043d\u0442\u0440\u0438\u0433\u043e\u0432\u0430\u043b \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0443 lookup \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430:<br \/>  1. \u041f\u043b\u043e\u0445\u0430\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u0438\u043d\u043d\u0430\u044f.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; query = SomeModel.objects.filter(user__savepoint__created_datetime__gte=last_week) <\/code><\/pre>\n<p>  \u0421\u0442\u0440\u043e\u043a\u0430 \u043f\u043b\u043e\u0445\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u0430, \u0442.\u00a0\u043a. \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0437\u0433\u043b\u044f\u0434\u0430 created_datetime \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u0443\u0442\u0430\u0442\u044c \u0441 created__datetime, \u043b\u0438\u0431\u043e \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u2014 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 user \u0438 savepoint. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 lookup \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u043f\u043e\u043b\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0440\u0438 \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0438 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u0432\u0438\u0434\u0443 \u00ab\u0431\u043e\u043b\u044c\u0448\u0435 \u043b\u0438\u0431\u043e \u0440\u0430\u0432\u043d\u043e\u00bb, \u043d\u043e \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 \u2014 \u044d\u0442\u043e \u0432\u0435\u0434\u044c \u043f\u043e\u0442\u0435\u0440\u044f \u0434\u0440\u0430\u0433\u043e\u0446\u0435\u043d\u043d\u044b\u0445 \u0441\u0435\u043a\u0443\u043d\u0434!<\/p>\n<p>  2. \u0422\u0440\u0443\u0434\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0438\u0441\u043a\u0430. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0448\u0435 \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u043f\u043e\u043b\u044e created_datetime.  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; query.order_by('user__savepoint__created_datetime') <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0434\u043b\u0438\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043d\u0430\u0431\u0440\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e, \u043f\u0440\u0438 \u0447\u0435\u043c \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0435\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0442.\u00a0\u043a. \u0432 \u043e\u0434\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443, \u0430 \u0432\u044b\u0448\u0435 \u2014 keyword \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442.<br \/>  \u041f\u0440\u0438\u0434\u0438\u0440\u0447\u0438\u0432\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043c\u0435\u0442\u0438\u0442, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 query_param = &#8216;user__savepoint_created_datetime&#8217; \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0445\u0430\u043a:  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; SomeModel.objects.filter(**{'{}_gte'.format(query_param): last_week}).order_by(query_param) <\/code><\/pre>\n<p>  \u041d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u0439, \u0442.\u00a0\u0435. \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u2014 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434, \u043e\u043d \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b.<br \/>  \u0418\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430, \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u0442\u043e\u0447\u043a\u0443. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f: __eq__, __gt__, __lt__ \u0438 \u0434\u0440.<br \/>  \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:   <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; SomeModel.user.savepoint.created_datetime &gt;= last_week <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u0442\u0430\u043a\u043e\u0435 \u0443\u0436 \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u0442.\u00a0\u043a. \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0430\u0442\u0447\u0438\u0442\u044c \u0434\u0436\u0430\u043d\u0433\u043e\u0432\u0441\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438 \u043f\u043e\u043b\u0435\u0439, \u0430 \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u0438\u0440\u0435. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u0438\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043b\u0438\u043d\u043d\u044b\u043c, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u043d\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0432\u043d\u044b\u043c, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432. \u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 Q \u2014 \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0442\u043a\u0438\u0439, \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e. \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u2014 \u0438 \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e S (\u043e\u0442 Sugar). \u0411\u0443\u0434\u0435\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a.  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; S.user.savepoint.created_datetime &gt;= last_week  {'user__savepoint__created_datetime__gte': last_week} <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e:  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; SomeModel.objects.filter(**(S.user.savepoint.created_datetime &gt;= last_week)) <\/code><\/pre>\n<p>  \u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043d\u0430\u043c \u0441\u043d\u043e\u0432\u0430 \u043f\u0440\u0438\u0434\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 Q \u2014 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u044f\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 filter, \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440!  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; S.user.savepoint.created_datetime &gt;= last_week Q(user__savepoint__created_datetime__gte=last_week)  &gt;&gt;&gt; SomeModel.objects.filter(S.user.savepoint.created_datetime &gt;= last_week) <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c, \u0434\u0435\u043b\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439. \u041d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 <a href=\"https:\/\/github.com\/Nepherhotep\/django-orm-sugar\">github.com\/Nepherhotep\/django-orm-sugar<\/a>.<\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 \u21161. \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f.<\/h2>\n<p>  \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0437\u0434\u0435\u0441\u044c <a href=\"https:\/\/docs.python.org\/2\/reference\/datamodel.html#object.__lt__\">docs.python.org\/2\/reference\/datamodel.html#object.__lt__<\/a> \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b. \u042d\u0442\u043e __lt__, __le__, __gt__, __ge__, __eq__, __ne__. \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0438\u0445, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 Q \u043e\u0431\u044a\u0435\u043a\u0442:  <\/p>\n<pre><code class=\"python\">def __ge__(self, value):     return Q(**{'{}__gte'.format(self.get_path()): value})  \u0438 \u0442.\u00a0\u0434. <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e is \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u043d\u0430 contains \u0432 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u043e\u043c \u0441\u0442\u0438\u043b\u0435:  <\/p>\n<pre><code class=\"python\">'substr' in S.user.username <\/code><\/pre>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"python\">def contains(self, value):     return Q(**{'{}__contains'.format(self.get_path()): value})  def in_list(self, value):     return Q(**{'{}__value'.format(self.get_path()): value}) <\/code><\/pre>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 in_range:  <\/p>\n<pre><code class=\"python\">def in_range(self, min_value, max_value):      return (self &lt;= min_value) & (self &gt;= max_value) <\/code><\/pre>\n<p>  \u0415\u0433\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 keyword \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; SomeModel.objects.filter(S.user.savepoint.created_datetime.in_range(month_ago, week_ago)) <\/code><\/pre>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 \u21162. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043f\u043e \u0442\u043e\u0447\u043a\u0435<\/h2>\n<p>  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; S.user.savepoint.create_datetime <\/code><\/pre>\n<p>  \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0431\u0443\u0434\u0435\u043c \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0430 \u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430. \u041d\u043e \u0442.\u00a0\u043a. \u0432\u044b\u0448\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0431\u0435\u0437 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0441\u0430\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0432\u043c\u0435\u043d\u044f\u0435\u043c\u043e \u2014 SugarQueryHelper.  <\/p>\n<pre><code class=\"python\">class SugarQueryHelper(object):     pass  S = SugarQueryHelper() <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0430 \u043b\u0435\u0442\u0443, \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 __getattr__ \u2014 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0435\u0441\u043b\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438.  <\/p>\n<pre><code class=\"python\">    def __getattr__(self, item):         return SugarQueryHelper() <\/code><\/pre>\n<p>  \u041d\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0435\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c Q \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441.  <\/p>\n<pre><code class=\"python\">class SugarQueryHelper(object):     def __init__(self, parent=None, name=''):         self.__parent = parent         self.__name = name      def __getattr__(self, item):         return SugarQueryHelper(self, item) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u0443\u0442\u0435\u0439, \u0438 \u043c\u043e\u0434\u0443\u043b\u044c \u0433\u043e\u0442\u043e\u0432!  <\/p>\n<pre><code class=\"python\">    def get_path(self):         if self.__parent:             parent_param = self.__parent.get_path()             if parent_param:                 # \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u043f\u0443\u0441\u0442\u043e\u0439 \u043f\u0443\u0442\u044c \u043e\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f                 return '__'.join([parent_param, self.__name])         # \u0432 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0438\u043c\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430         return self.__name <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 SugarQueryHelper, \u043d\u043e \u0438 \u0434\u043b\u044f \u0442\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 order_by \u0438\u043b\u0438 select_related.<br \/>  \u041f\u043e\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u043e\u0437\u0432\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0432\u044b\u0448\u0435 \u2014 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; sdate = S.user.savepoint.created_datetime &gt;&gt;&gt; SomeModel.filter(sdate &gt;= last_week).order_by(sdate.get_path()) <\/code><\/pre>\n<h2>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435.<\/h2>\n<p>  \u041c\u043e\u0434\u0443\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u043d\u0435\u043f\u043b\u043e\u0445, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u043e \u0435\u0441\u0442\u044c \u0432\u0435\u0449\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c.<br \/>  \u0415\u0441\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0442\u043e S \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u043f\u043e\u043b\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u044b \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 contains, icontains, exact \u0438 \u0442.\u00a0\u0434. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u0438\u0434\u0435\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f, \u043d\u043e \u043f\u043e \u0437\u0430\u043a\u043e\u043d\u0443 \u041c\u0435\u0440\u0444\u0438 \u0442\u0430\u043a\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0443\u0442.<br \/>  \u0427\u0442\u043e \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c? \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0445\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u2014 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 __call__, \u0438 \u0435\u0441\u043b\u0438 \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0442\u043e \u0438\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u043f\u0443\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0430\u043c\u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0441 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f, \u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e (\u0431\u0435\u0437 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f) \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440:  <\/p>\n<pre><code class=\"python\">@register_hook('icontains') def _icontains(self, value):     return Q(...) <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u0435\u043d\u0435\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445. \u0412 \u0438\u0442\u043e\u0433\u0435, \u0442.\u043a. \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 Q \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0447\u0435\u0440\u0435\u0437 keywords \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0435 \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e (\u0432\u0435\u0440\u0441\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 \u0432\u0435\u0442\u043a\u0435 special_names).<br \/>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e Q \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c. \u0422.\u0435. \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c S \u0438 Q, \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e Q \u0432 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0443 Q \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438. \u0420\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043d\u0430\u0445\u0440\u0430\u043f\u043e\u043c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u043a\u0430\u043a \u0435\u0441\u0442\u044c.<br \/>  \u0415\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 <a href=\"https:\/\/docs.djangoproject.com\/en\/1.8\/topics\/db\/managers\/#custom-managers\">docs.djangoproject.com\/en\/1.8\/topics\/db\/managers\/#custom-managers<\/a>. \u0422\u043e\u0433\u0434\u0430, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0432 \u0435\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0438\u0434\u0430:  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; SomeModel.s_objects.user.age &gt;= 16 &lt;QuerySet&gt; <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u043b\u043e\u043c\u0430\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0432 \u0434\u0436\u0430\u043d\u0433\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0430. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043f\u043e\u043b\u044c\u0437\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0430:  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; (SomeModel.s_objects.user.age &gt;= 16) & (SomeModel.s_objects.user.is_active == True) vs &gt;&gt;&gt; SomeModel.objects.filter((S.user.age &gt;= 16) & (S.user.is_active == True)) <\/code><\/pre>\n<p>  \u041d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u043a\u0440\u0430\u0442\u043a\u043e, \u043d\u0435 \u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438? \u041d\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u0443\u0436\u0435 \u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445, \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0441\u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u2014 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0432\u0435\u0434\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442!<\/p>\n<h2>\u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u0448\u0442\u0443\u043a\u0443 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u0441\u0435 \u0442\u044f\u0436\u0435\u043b\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043b\u043e\u0436\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u043b\u0435\u0447\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u0436\u0430\u043d\u0433\u0438 \u2014 \u0432\u0435\u0434\u044c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u0430\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u0435\u043c\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u2014 \u0447\u0438\u0441\u043b\u043e, \u0434\u0430\u0442\u0443 \u0438\u043b\u0438 F-\u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b \u043b\u0438 \u0438\u043c\u0435\u043d\u0430 \u043f\u043e\u043b\u0435\u0439 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0422\u0430\u043a\u0436\u0435, \u043c\u043e\u0434\u0443\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439, \u0442\u0430\u043a \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u043f\u0438\u0442\u043e\u043d\u0430.<br \/>  \u0415\u0441\u043b\u0438 \u0443 \u043a\u043e\u0433\u043e-\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0438\u0434\u0435\u0438, \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u2014 \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0438\u043b\u0438 \u0448\u043b\u0438\u0442\u0435 \u043f\u0443\u043b \u0440\u0435\u043a\u0432\u0435\u0441\u0442\u044b.<br \/>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!     \t<\/p>\n<div class=\"clear\"><\/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=\"http:\/\/habrahabr.ru\/post\/263821\/\"> http:\/\/habrahabr.ru\/post\/263821\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/0f0\/925\/186\/0f092518650f41a38ae9f8a83f01206d.jpg\"\/><br \/>  \u0424\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Django, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0434\u043b\u044f \u044f\u0437\u044b\u043a\u0430 Python. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0440\u0438 \u0432\u0441\u0435\u0439 \u0435\u0433\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438, \u0447\u0430\u0441\u0442\u043e \u043a\u0440\u0438\u0442\u0438\u043a\u0443\u044e\u0442 \u0435\u0433\u043e ORM \u2014 \u0430 \u0438\u043c\u0435\u043d\u043d\u043e lookup \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0442\u0430\u043a\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d \u2014 \u043e\u043d \u043b\u0435\u0433\u043e\u043a \u0432 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c, \u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u043f\u0440\u043e\u0441\u0442, \u043a\u0430\u043a \u0448\u0432\u0430\u0431\u0440\u0430. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043f\u0440\u044f\u043c\u043e \u0438\u0437\u044f\u0449\u0435\u0441\u0442\u0432\u0430. \u041d\u043e \u043a\u0440\u0430\u0441\u043e\u0442\u0430 \u2014 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0415\u0441\u043b\u0438 \u0437\u0430\u0438\u043d\u0442\u0440\u0438\u0433\u043e\u0432\u0430\u043b \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.  <\/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-262568","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/262568","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=262568"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/262568\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=262568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=262568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=262568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}