""" Declaration of custom fields to allows selection of translatable fields.
We add a `translatable` attribute at True to easily filter fields to translate. """

from django.conf import settings
from django.db import models


class LanguageField(models.CharField):
    """
    A language field for Django models.
    """

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('max_length', 5)
        kwargs.setdefault('choices', sorted(settings.LANGUAGES, key=lambda x: x[1]))
        super().__init__(*args, **kwargs)
