Skip to content

Commit

Permalink
fix: added missing methods to SingleTranslationObject to make it work…
Browse files Browse the repository at this point in the history
… with django 4
  • Loading branch information
bnznamco committed May 19, 2022
1 parent 503e1f6 commit b6bae7c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion hvad/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class SingleTranslationObject(ForeignObject):
Allows delegating translation loading to Django's select_related.
"""
requires_unique_target = False

db_constraint = False

def __init__(self, model, translations_model=None):
if isinstance(model, str):
model = apps.get_model(model)
Expand All @@ -140,6 +141,20 @@ def get_extra_restriction(self, *args):
return LanguageConstraint(
Col(alias, related_model._meta.get_field('language_code'), models.CharField())
)

def db_type(self, connection):
return self.target_field.rel_db_type(connection=connection)

def db_parameters(self, connection):
return {"type": self.db_type(connection), "check": self.db_check(connection)}

def get_attname(self):
return "%s_id" % self.name

def get_attname_column(self):
attname = self.get_attname()
column = self.db_column or attname
return attname, column

def get_path_info(self, filtered_relation=None):
""" Mark the field as indirect so most Django automation ignores it """
Expand Down

0 comments on commit b6bae7c

Please sign in to comment.