|
2 | 2 | The `compat` module provides support for backwards compatibility with older |
3 | 3 | versions of Django/Python, and compatibility wrappers around optional packages. |
4 | 4 | """ |
5 | | -import django |
6 | | -from django.db import models |
7 | | -from django.db.models.constants import LOOKUP_SEP |
8 | | -from django.db.models.sql.query import Node |
9 | 5 | from django.views.generic import View |
10 | 6 |
|
11 | 7 |
|
@@ -141,52 +137,8 @@ def md_filter_add_syntax_highlight(md): |
141 | 137 | return False |
142 | 138 |
|
143 | 139 |
|
144 | | -if django.VERSION >= (5, 1): |
145 | | - # Django 5.1+: use the stock ip_address_validators function |
146 | | - # Note: Before Django 5.1, ip_address_validators returns a tuple containing |
147 | | - # 1) the list of validators and 2) the error message. Starting from |
148 | | - # Django 5.1 ip_address_validators only returns the list of validators |
149 | | - from django.core.validators import ip_address_validators |
150 | | - |
151 | | - def get_referenced_base_fields_from_q(q): |
152 | | - return q.referenced_base_fields |
153 | | - |
154 | | -else: |
155 | | - # Django <= 5.1: create a compatibility shim for ip_address_validators |
156 | | - from django.core.validators import \ |
157 | | - ip_address_validators as _ip_address_validators |
158 | | - |
159 | | - def ip_address_validators(protocol, unpack_ipv4): |
160 | | - return _ip_address_validators(protocol, unpack_ipv4)[0] |
161 | | - |
162 | | - # Django < 5.1: create a compatibility shim for Q.referenced_base_fields |
163 | | - # https://github.com/django/django/blob/5.1a1/django/db/models/query_utils.py#L179 |
164 | | - def _get_paths_from_expression(expr): |
165 | | - if isinstance(expr, models.F): |
166 | | - yield expr.name |
167 | | - elif hasattr(expr, 'flatten'): |
168 | | - for child in expr.flatten(): |
169 | | - if isinstance(child, models.F): |
170 | | - yield child.name |
171 | | - elif isinstance(child, models.Q): |
172 | | - yield from _get_children_from_q(child) |
173 | | - |
174 | | - def _get_children_from_q(q): |
175 | | - for child in q.children: |
176 | | - if isinstance(child, Node): |
177 | | - yield from _get_children_from_q(child) |
178 | | - elif isinstance(child, tuple): |
179 | | - lhs, rhs = child |
180 | | - yield lhs |
181 | | - if hasattr(rhs, 'resolve_expression'): |
182 | | - yield from _get_paths_from_expression(rhs) |
183 | | - elif hasattr(child, 'resolve_expression'): |
184 | | - yield from _get_paths_from_expression(child) |
185 | | - |
186 | | - def get_referenced_base_fields_from_q(q): |
187 | | - return { |
188 | | - child.split(LOOKUP_SEP, 1)[0] for child in _get_children_from_q(q) |
189 | | - } |
| 140 | +def get_referenced_base_fields_from_q(q): |
| 141 | + return q.referenced_base_fields |
190 | 142 |
|
191 | 143 |
|
192 | 144 | # `separators` argument to `json.dumps()` differs between 2.x and 3.x |
|
0 commit comments