Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes necessary for running on Django 3.2 #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions linguo/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ def get_fields_to_translatable_models(model):
results = []
from linguo.models import MultilingualModel # to avoid circular import

for field_name in model._meta.get_all_field_names():
field_object, modelclass, direct, m2m = model._meta.get_field_by_name(field_name)
for field in model._meta.get_fields():
field_object = model._meta.get_field(field.name)
direct = hasattr(field_object, 'related_model')
if direct and isinstance(field_object, RelatedField):
if issubclass(field_object.related.parent_model, MultilingualModel):
results.append((field_name, field_object.related.parent_model))
if issubclass(field_object.related_model, MultilingualModel):
results.append((field.name, field_object.related_model))
return results


Expand All @@ -66,13 +67,14 @@ def __init__(self, *args, **kwargs):
ordering.append(rewrite_lookup_key(self.model, key))
self.query.add_ordering(*ordering)

def _filter_or_exclude(self, negate, *args, **kwargs):
def _filter_or_exclude(self, negate, args, kwargs):
kwargs_new = {}
for key, val in kwargs.items():
new_key = rewrite_lookup_key(self.model, key)
del kwargs[key]
kwargs[new_key] = val
kwargs_new[new_key] = val
kwargs = kwargs_new

return super(MultilingualQuerySet, self)._filter_or_exclude(negate, *args, **kwargs)
return super(MultilingualQuerySet, self)._filter_or_exclude(negate, args, kwargs)

def order_by(self, *field_names):
new_args = []
Expand Down
14 changes: 11 additions & 3 deletions linguo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ def rewrite_unique_together(cls, local_trans_fields, attrs):
return attrs


class MultilingualModel(models.Model):
__metaclass__ = MultilingualModelBase

class MultilingualModel(models.Model, metaclass=MultilingualModelBase):
objects = MultilingualManager()

class Meta:
Expand Down Expand Up @@ -202,3 +200,13 @@ def translate(self, language, **kwargs):
setattr(self, key, val) # Set values on the object
# Now switch back
self._force_language = old_forced_language

def get_deferred_fields(self):
"""
Return a set containing names of deferred fields for this instance.
"""
return {
f.attname for f in self._meta.concrete_fields
if f.attname not in self.__dict__ and \
f.attname not in self._meta.translatable_fields
}