Hide keyboard shortcuts

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 

2 

3from django.conf import settings 

4from django.db import models 

5from django.utils.translation import ugettext_lazy as _ 

6 

7# Exports 

8 

9__all__ = ( 

10 "LookupModel", 

11 "IntegerLookupModel", 

12 "StringLookupModel", 

13) 

14 

15# Constants 

16 

17AUTH_USER_MODEL = settings.AUTH_USER_MODEL 

18 

19# Abstract Models 

20 

21 

22class LookupModel(models.Model): 

23 """Base class for lookup models.""" 

24 

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 ) 

32 

33 description = models.TextField( 

34 blank=True, 

35 help_text=_("Brief description of the entry."), 

36 null=True 

37 ) 

38 

39 is_enabled = models.BooleanField( 

40 _("enabled"), 

41 default=True, 

42 help_text=_("Indicates the lookup is enabled for use.") 

43 ) 

44 

45 label = models.CharField( 

46 _("label"), 

47 help_text=_("Official name or title for the entry."), 

48 max_length=128, 

49 unique=True 

50 ) 

51 

52 class Meta: 

53 abstract = True 

54 

55 def __contains__(self, item): 

56 # noinspection PyUnresolvedReferences 

57 return item in self.value 

58 

59 def __str__(self): 

60 return self.label 

61 

62 def get_choice_name(self): 

63 """Comply with the API for :py:class:`supdjango.db.display.models.DisplayNameMixin`.""" 

64 return self.label 

65 

66 def get_display_name(self): 

67 """Comply with the API for :py:class:`supdjango.db.display.models.DisplayNameMixin`.""" 

68 return self.label 

69 

70 

71class IntegerLookupModel(LookupModel): 

72 """Create a lookup with an integer value.""" 

73 

74 value = models.IntegerField( 

75 _("value"), 

76 help_text=_("The value of the lookup."), 

77 unique=True 

78 ) 

79 

80 class Meta: 

81 abstract = True 

82 

83 

84class StringLookupModel(LookupModel): 

85 """Create a lookup with a string value.""" 

86 

87 value = models.CharField( 

88 _("value"), 

89 help_text=_("The value of the lookup."), 

90 max_length=64, 

91 unique=True 

92 ) 

93 

94 class Meta: 

95 abstract = True