# Imports
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
# Exports
__all__ = (
"PrimaryManager",
)
# Managers
[docs]class PrimaryManager(models.Manager):
"""Supports the ``PrimaryModel``.
.. code-block:: py
from superdjango.db.primary.managers import PrimaryManager
from superdjango.db.primary.models import PrimaryModel
class EmergencyContact(PrimaryModel):
employee = models.ForeignKey(Employee, related_name="emergency_contacts")
# ...
employee = Employee.objects.get(pk=1)
contact = employee.emergency_contacts.primary()
"""
[docs] def primary(self):
"""Get the primary record."""
try:
return self.get_queryset().get(is_primary=True)
except ObjectDoesNotExist:
return None