dj22: do not backport jsonb key transforms (#51516)
This commit is contained in:
parent
3f56b2ad0b
commit
7df6f0ae0c
|
@ -14,13 +14,16 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.contrib.postgres.fields import jsonb
|
||||
import django
|
||||
|
||||
from django.db.models import Transform, TextField, DateField
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class KeyTransform(Transform):
|
||||
from django.contrib.postgres.fields import jsonb
|
||||
try:
|
||||
from django.contrib.postgres.fields.jsonb import KeyTransform, KeyTransformTextLookupMixin
|
||||
except ImportError:
|
||||
# backport from Django 2.x
|
||||
class KeyTransform(Transform):
|
||||
operator = '->'
|
||||
nested_operator = '#>'
|
||||
|
||||
|
@ -45,17 +48,14 @@ class KeyTransform(Transform):
|
|||
lookup = "%s" % self.key_name
|
||||
return "(%s %s %s)" % (lhs, self.operator, lookup), params
|
||||
|
||||
jsonb.KeyTransform = KeyTransform
|
||||
|
||||
jsonb.KeyTransform = KeyTransform
|
||||
|
||||
|
||||
class KeyTextTransform(KeyTransform):
|
||||
class KeyTextTransform(KeyTransform):
|
||||
operator = '->>'
|
||||
nested_operator = '#>>'
|
||||
_output_field = TextField()
|
||||
|
||||
|
||||
class KeyTransformTextLookupMixin(object):
|
||||
class KeyTransformTextLookupMixin(object):
|
||||
"""
|
||||
Mixin for combining with a lookup expecting a text lhs from a JSONField
|
||||
key lookup. Make use of the ->> operator instead of casting key values to
|
||||
|
|
Loading…
Reference in New Issue