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.core.exceptions import ObjectDoesNotExist 

4from django.db import models 

5 

6# Exports 

7 

8__all__ = ( 

9 "PrimaryManager", 

10) 

11 

12 

13# Managers 

14 

15 

16class PrimaryManager(models.Manager): 

17 """Supports the ``PrimaryModel``. 

18 

19 .. code-block:: py 

20 

21 from superdjango.db.primary.managers import PrimaryManager 

22 from superdjango.db.primary.models import PrimaryModel 

23 

24 class EmergencyContact(PrimaryModel): 

25 employee = models.ForeignKey(Employee, related_name="emergency_contacts") 

26 # ... 

27 

28 employee = Employee.objects.get(pk=1) 

29 contact = employee.emergency_contacts.primary() 

30 

31 """ 

32 

33 def primary(self): 

34 """Get the primary record.""" 

35 try: 

36 return self.get_queryset().get(is_primary=True) 

37 except ObjectDoesNotExist: 

38 return None