|
|
@@ -5,6 +5,7 @@ from functools import cached_property
|
|
|
from django.contrib.contenttypes.fields import GenericRelation
|
|
|
from django.core.validators import ValidationError
|
|
|
from django.db import models
|
|
|
+from django.db.models import Q
|
|
|
from django.utils import timezone
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
from taggit.managers import TaggableManager
|
|
|
@@ -363,6 +364,26 @@ class ContactsMixin(models.Model):
|
|
|
class Meta:
|
|
|
abstract = True
|
|
|
|
|
|
+ def get_contacts(self, inherited=True):
|
|
|
+ """
|
|
|
+ Return a `QuerySet` matching all contacts assigned to this object.
|
|
|
+
|
|
|
+ :param inherited: If `True`, inherited contacts from parent objects are included.
|
|
|
+ """
|
|
|
+ from tenancy.models import ContactAssignment
|
|
|
+ from . import NestedGroupModel
|
|
|
+
|
|
|
+ filter = Q(
|
|
|
+ object_type=ObjectType.objects.get_for_model(self),
|
|
|
+ object_id__in=(
|
|
|
+ self.get_ancestors(include_self=True)
|
|
|
+ if (isinstance(self, NestedGroupModel) and inherited)
|
|
|
+ else [self.pk]
|
|
|
+ ),
|
|
|
+ )
|
|
|
+
|
|
|
+ return ContactAssignment.objects.filter(filter)
|
|
|
+
|
|
|
|
|
|
class BookmarksMixin(models.Model):
|
|
|
"""
|