Skip to content

Commit

Permalink
Add support for dj32
Browse files Browse the repository at this point in the history
  • Loading branch information
LegoStormtroopr committed Sep 9, 2022
1 parent 7b6b3c0 commit ab7b27d
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 201 deletions.
13 changes: 6 additions & 7 deletions garnett/expressions.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
from django.db.models import F
from django.db.models.fields.json import KeyTextTransform

from garnett.utils import get_current_language
from garnett.utils import get_current_language_code
from garnett.fields import TranslatedField


# Based on: https://code.djangoproject.com/ticket/29769#comment:5
# Updated comment here
# https://code.djangoproject.com/ticket/31639
class LangF(F):
def resolve_expression(
self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False
):
rhs = super().resolve_expression(query, allow_joins, reuse, summarize, for_save)
def resolve_expression(self, *args, **kwargs):
print(args, kwargs)
rhs = super().resolve_expression(*args, **kwargs)
if isinstance(rhs.field, TranslatedField):
field_list = self.name.split("__")
# TODO: should this always lookup lang
if len(field_list) == 1:
# Lookup current lang for one field
field_list.extend([get_current_language()])
field_list.extend([get_current_language_code()])
for name in field_list[1:]:
# Perform key lookups along path
rhs = KeyTextTransform(name, rhs)
Expand All @@ -30,4 +29,4 @@ class L(KeyTextTransform):
"""Expression to return the current language"""

def __init__(self, *args, **kwargs):
super().__init__(get_current_language(), *args, **kwargs)
super().__init__(get_current_language_code(), *args, **kwargs)
2 changes: 1 addition & 1 deletion garnett/lookups.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db.models import lookups
from django.db.models.fields import json, CharField
from django.db.models.functions import Cast
from django.contrib.postgres.fields.jsonb import KeyTextTransform
from django.db.models.fields.json import KeyTextTransform
from django.contrib.postgres.lookups import SearchLookup, TrigramSimilar
from django.contrib.postgres.search import TrigramSimilarity

Expand Down
Loading

0 comments on commit ab7b27d

Please sign in to comment.