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.core.exceptions import ObjectDoesNotExist
4from django.db import models
6# Exports
8__all__ = (
9 "PrimaryManager",
10)
13# Managers
16class PrimaryManager(models.Manager):
17 """Supports the ``PrimaryModel``.
19 .. code-block:: py
21 from superdjango.db.primary.managers import PrimaryManager
22 from superdjango.db.primary.models import PrimaryModel
24 class EmergencyContact(PrimaryModel):
25 employee = models.ForeignKey(Employee, related_name="emergency_contacts")
26 # ...
28 employee = Employee.objects.get(pk=1)
29 contact = employee.emergency_contacts.primary()
31 """
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