"""This module contains the fields for the ``django-discover`` app"""

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)
