Source code for superdjango.forms.fields

# Imports

from django import forms
# from django.utils.translation import gettext_lazy as _
# from superdjango.contrib.i18n.languages import COMMON_LANGUAGE_CHOICES, LANGUAGE_MAX_CHOICE_LENGTH
# from superdjango.contrib.i18n.timezones import COMMON_TIMEZONE_CHOICES, TIMEZONE_MAX_CHOICE_LENGTH

# Exports

__all__ = (
    "FullNameChoiceField",
)

# Fields


[docs]class FullNameChoiceField(forms.ModelChoiceField): """If available, uses the full name of the user for the dropdown instead of the user name. **Usage** In your form: .. code-block:: python from django.contrib.auth import get_user_model user_model = get_user_model() class MyModelForm(ModelForm): requested_by = FullNameChoiceField( queryset=user_model.objects.filter(is_staff=True), label=_("requested by") ) """
[docs] def label_from_instance(self, obj): return obj.get_full_name() or obj.username
# class SlugFromField(forms.SlugField): # """A slug field that provides automated slugify.""" # description = _("A slug field that provides automated slugify.") # # def media