Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Imports
3from django.conf import settings
4from django.db import models
5from django.utils.translation import ugettext_lazy as _
7# Exports
9__all__ = (
10 "LookupModel",
11 "IntegerLookupModel",
12 "StringLookupModel",
13)
15# Constants
17AUTH_USER_MODEL = settings.AUTH_USER_MODEL
19# Abstract Models
22class LookupModel(models.Model):
23 """Base class for lookup models."""
25 abbr = models.CharField(
26 _("abbreviation"),
27 blank=True,
28 help_text=_("Enter the common abbreviation for the entry, if any."),
29 max_length=16,
30 null=True
31 )
33 description = models.TextField(
34 blank=True,
35 help_text=_("Brief description of the entry."),
36 null=True
37 )
39 is_enabled = models.BooleanField(
40 _("enabled"),
41 default=True,
42 help_text=_("Indicates the lookup is enabled for use.")
43 )
45 label = models.CharField(
46 _("label"),
47 help_text=_("Official name or title for the entry."),
48 max_length=128,
49 unique=True
50 )
52 class Meta:
53 abstract = True
55 def __contains__(self, item):
56 # noinspection PyUnresolvedReferences
57 return item in self.value
59 def __str__(self):
60 return self.label
62 def get_choice_name(self):
63 """Comply with the API for :py:class:`supdjango.db.display.models.DisplayNameMixin`."""
64 return self.label
66 def get_display_name(self):
67 """Comply with the API for :py:class:`supdjango.db.display.models.DisplayNameMixin`."""
68 return self.label
71class IntegerLookupModel(LookupModel):
72 """Create a lookup with an integer value."""
74 value = models.IntegerField(
75 _("value"),
76 help_text=_("The value of the lookup."),
77 unique=True
78 )
80 class Meta:
81 abstract = True
84class StringLookupModel(LookupModel):
85 """Create a lookup with a string value."""
87 value = models.CharField(
88 _("value"),
89 help_text=_("The value of the lookup."),
90 max_length=64,
91 unique=True
92 )
94 class Meta:
95 abstract = True