dj22: do not backport jsonb key transforms (#51516)

This commit is contained in:
Benjamin Dauvergne 2021-03-01 13:43:21 +01:00
parent 3f56b2ad0b
commit 7df6f0ae0c
1 changed files with 46 additions and 46 deletions

View File

@ -14,12 +14,15 @@
# 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
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,16 +48,13 @@ class KeyTransform(Transform):
lookup = "%s" % self.key_name
return "(%s %s %s)" % (lhs, self.operator, lookup), params
jsonb.KeyTransform = KeyTransform
class KeyTextTransform(KeyTransform):
operator = '->>'
nested_operator = '#>>'
_output_field = TextField()
class KeyTransformTextLookupMixin(object):
"""
Mixin for combining with a lookup expecting a text lhs from a JSONField