Source code for superdjango.db.lookups.models

# Imports

from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _

# Exports

__all__ = (
    "LookupModel",
    "IntegerLookupModel",
    "StringLookupModel",
)

# Constants

AUTH_USER_MODEL = settings.AUTH_USER_MODEL

# Abstract Models


[docs]class LookupModel(models.Model): """Base class for lookup models.""" abbr = models.CharField( _("abbreviation"), blank=True, help_text=_("Enter the common abbreviation for the entry, if any."), max_length=16, null=True ) description = models.TextField( blank=True, help_text=_("Brief description of the entry."), null=True ) is_enabled = models.BooleanField( _("enabled"), default=True, help_text=_("Indicates the lookup is enabled for use.") ) label = models.CharField( _("label"), help_text=_("Official name or title for the entry."), max_length=128, unique=True ) class Meta: abstract = True def __contains__(self, item): # noinspection PyUnresolvedReferences return item in self.value def __str__(self): return self.label
[docs] def get_choice_name(self): """Comply with the API for :py:class:`supdjango.db.display.models.DisplayNameMixin`.""" return self.label
[docs] def get_display_name(self): """Comply with the API for :py:class:`supdjango.db.display.models.DisplayNameMixin`.""" return self.label
[docs]class IntegerLookupModel(LookupModel): """Create a lookup with an integer value.""" value = models.IntegerField( _("value"), help_text=_("The value of the lookup."), unique=True ) class Meta: abstract = True
[docs]class StringLookupModel(LookupModel): """Create a lookup with a string value.""" value = models.CharField( _("value"), help_text=_("The value of the lookup."), max_length=64, unique=True ) class Meta: abstract = True