# Path: modeltrans/conf.py
# def get_default_language():
#     return settings.LANGUAGE_CODE
# 
# Path: modeltrans/fields.py
# class TranslationField(JSONField):
#     """
#     This model field is used to store the translations in the translated model.
# 
#     Arguments:
#         fields (iterable): List of model field names to make translatable.
#         required_languages (iterable or dict): List of languages required for the model.
#             If a dict is supplied, the keys must be translated field names with the value
#             containing a list of required languages for that specific field.
#         virtual_fields (bool): If `False`, do not add virtual fields to access
#             translated values with.
#             Set to `True` during migration from django-modeltranslation to prevent
#             collisions with it's database fields while having the `i18n` field available.
#         fallback_language_field: If not None, this should be the name of the field containing a
#             language code to use as the first language in any fallback chain.
#             For example: if you have a model instance with 'nl' as language_code, and set
#             fallback_language_field='language_code', 'nl' will always be tried after the current
#             language before any other language.
#     """
# 
#     description = "Translation storage for a model"
# 
#     def __init__(
#         self,
#         fields=None,
#         required_languages=None,
#         virtual_fields=True,
#         fallback_language_field=None,
#         *args,
#         **kwargs,
#     ):
#         self.fields = fields or ()
#         self.required_languages = required_languages or ()
#         self.virtual_fields = virtual_fields
#         self.fallback_language_field = fallback_language_field
# 
#         kwargs["editable"] = False
#         kwargs["null"] = True
#         super().__init__(*args, **kwargs)
# 
#     def deconstruct(self):
#         name, path, args, kwargs = super().deconstruct()
# 
#         del kwargs["editable"]
#         del kwargs["null"]
#         kwargs["fields"] = self.fields
#         kwargs["required_languages"] = self.required_languages
#         kwargs["virtual_fields"] = self.virtual_fields
# 
#         return name, path, args, kwargs
# 
#     def get_translated_fields(self):
#         """Return a generator for all translated fields."""
#         for field in self.model._meta.get_fields():
#             if isinstance(field, TranslatedVirtualField):
#                 yield field
# 
#     def contribute_to_class(self, cls, name):
#         if name != "i18n":
#             raise ImproperlyConfigured('{} must have name "i18n"'.format(self.__class__.__name__))
# 
#         super().contribute_to_class(cls, name)
# 
# Path: modeltrans/manager.py
# class MultilingualManager(Manager):
#     """
#     When adding the `modeltrans.fields.TranslationField` to a model, MultilingualManager is automatically
#     mixed in to the manager class of that model.
# 
#     If you want to use translated fields when building the query from a related model, you need to add
#     ``objects = MultilingualManager()`` to the model you want to build the query from.
# 
#     For example, ``Category`` needs ``objects = MultilingualManager()`` in order to allow
#     ``Category.objects.filter(blog__title_i18n__icontains="django")``::
# 
#         class Category(models.Model):
#             title = models.CharField(max_length=255)
# 
#             objects = MultilingualManager()  # required to use translated fields of Blog.
# 
#         class Blog(models.Model):
#             title = models.CharField(max_length=255)
#             body = models.TextField(null=True)
#             category = models.ForeignKey(Category, null=True, blank=True, on_delete=models.CASCADE)
# 
#             i18n = TranslationField(fields=("title", "body"))
#     """
# 
#     use_for_related_fields = True
# 
#     def _patch_queryset(self, qs):
#         qs.__class__ = multilingual_queryset_factory(qs.__class__, instantiate=False)
#         return qs
# 
#     def get_queryset(self):
#         """
#         This method is repeated because some managers that don't use super() or alter the QuerySet class
#         may return QuerySet that is not subclass of MultilingualQuerySet.
#         """
#         qs = super().get_queryset()
#         if isinstance(qs, MultilingualQuerySet):
#             # Is already patched
#             return qs
#         return self._patch_queryset(qs)


from django.db import models
from modeltrans.conf import get_default_language
from modeltrans.fields import TranslationField
from modeltrans.manager import MultilingualManager
    from django.db.models import JSONField  # django==3.1 moved json field
    from django.contrib.postgres.fields import JSONField


try:
except ImportError:


class CategoryQueryset(models.QuerySet):
    """
    Custom manager to make sure pickling on-the-fly created classes
    can be pickled, see test_querysets.py::PickleTest
    """


class Category(models.Model):

    name = models.CharField(max_length=255)
    title = models.CharField(max_length=255)


# Path: modeltrans/conf.py
# def get_default_language():
#     return settings.LANGUAGE_CODE
# 
# Path: modeltrans/fields.py
# class TranslationField(JSONField):
#     """
#     This model field is used to store the translations in the translated model.
# 
#     Arguments:
#         fields (iterable): List of model field names to make translatable.
#         required_languages (iterable or dict): List of languages required for the model.
#             If a dict is supplied, the keys must be translated field names with the value
#             containing a list of required languages for that specific field.
#         virtual_fields (bool): If `False`, do not add virtual fields to access
#             translated values with.
#             Set to `True` during migration from django-modeltranslation to prevent
#             collisions with it's database fields while having the `i18n` field available.
#         fallback_language_field: If not None, this should be the name of the field containing a
#             language code to use as the first language in any fallback chain.
#             For example: if you have a model instance with 'nl' as language_code, and set
#             fallback_language_field='language_code', 'nl' will always be tried after the current
#             language before any other language.
#     """
# 
#     description = "Translation storage for a model"
# 
#     def __init__(
#         self,
#         fields=None,
#         required_languages=None,
#         virtual_fields=True,
#         fallback_language_field=None,
#         *args,
#         **kwargs,
#     ):
#         self.fields = fields or ()
#         self.required_languages = required_languages or ()
#         self.virtual_fields = virtual_fields
#         self.fallback_language_field = fallback_language_field
# 
#         kwargs["editable"] = False
#         kwargs["null"] = True
#         super().__init__(*args, **kwargs)
# 
#     def deconstruct(self):
#         name, path, args, kwargs = super().deconstruct()
# 
#         del kwargs["editable"]
#         del kwargs["null"]
#         kwargs["fields"] = self.fields
#         kwargs["required_languages"] = self.required_languages
#         kwargs["virtual_fields"] = self.virtual_fields
# 
#         return name, path, args, kwargs
# 
#     def get_translated_fields(self):
#         """Return a generator for all translated fields."""
#         for field in self.model._meta.get_fields():
#             if isinstance(field, TranslatedVirtualField):
#                 yield field
# 
#     def contribute_to_class(self, cls, name):
#         if name != "i18n":
#             raise ImproperlyConfigured('{} must have name "i18n"'.format(self.__class__.__name__))
# 
#         super().contribute_to_class(cls, name)
# 
# Path: modeltrans/manager.py
# class MultilingualManager(Manager):
#     """
#     When adding the `modeltrans.fields.TranslationField` to a model, MultilingualManager is automatically
#     mixed in to the manager class of that model.
# 
#     If you want to use translated fields when building the query from a related model, you need to add
#     ``objects = MultilingualManager()`` to the model you want to build the query from.
# 
#     For example, ``Category`` needs ``objects = MultilingualManager()`` in order to allow
#     ``Category.objects.filter(blog__title_i18n__icontains="django")``::
# 
#         class Category(models.Model):
#             title = models.CharField(max_length=255)
# 
#             objects = MultilingualManager()  # required to use translated fields of Blog.
# 
#         class Blog(models.Model):
#             title = models.CharField(max_length=255)
#             body = models.TextField(null=True)
#             category = models.ForeignKey(Category, null=True, blank=True, on_delete=models.CASCADE)
# 
#             i18n = TranslationField(fields=("title", "body"))
#     """
# 
#     use_for_related_fields = True
# 
#     def _patch_queryset(self, qs):
#         qs.__class__ = multilingual_queryset_factory(qs.__class__, instantiate=False)
#         return qs
# 
#     def get_queryset(self):
#         """
#         This method is repeated because some managers that don't use super() or alter the QuerySet class
#         may return QuerySet that is not subclass of MultilingualQuerySet.
#         """
#         qs = super().get_queryset()
#         if isinstance(qs, MultilingualQuerySet):
#             # Is already patched
#             return qs
#         return self._patch_queryset(qs)


# Path: tests/app/models.py
from django.db import models
from modeltrans.conf import get_default_language
from modeltrans.fields import TranslationField
from modeltrans.manager import MultilingualManager
    from django.db.models import JSONField  # django==3.1 moved json field
    from django.contrib.postgres.fields import JSONField



try:
except ImportError:


class CategoryQueryset(models.QuerySet):
    """
    Custom manager to make sure pickling on-the-fly created classes
    can be pickled, see test_querysets.py::PickleTest
    """


class Category(models.Model):

    name = models.CharField(max_length=255)
    title = models.CharField(max_length=255)


    i18n = TranslationField(fields=("name", "title"))