Coverage for core/querysets.py: 85%
13 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
1from django.apps import apps
2from django.contrib.contenttypes.models import ContentType
3from django.db.utils import ProgrammingError
5from utilities.querysets import RestrictedQuerySet
7__all__ = (
8 'ObjectChangeQuerySet',
9)
12class ObjectChangeQuerySet(RestrictedQuerySet):
14 def valid_models(self):
15 # Exclude any change records which refer to an instance of a model that's no longer installed. This
16 # can happen when a plugin is removed but its data remains in the database, for example.
17 try:
18 content_types = ContentType.objects.get_for_models(*apps.get_models()).values()
19 except ProgrammingError:
20 # Handle the case where the database schema has not yet been initialized
21 content_types = ContentType.objects.none()
23 content_type_ids = set(
24 ct.pk for ct in content_types
25 )
26 return self.filter(changed_object_type_id__in=content_type_ids)