diff --git a/netbox/extras/filters.py b/netbox/extras/filters.py index afe3bff16..3ac25eec4 100644 --- a/netbox/extras/filters.py +++ b/netbox/extras/filters.py @@ -135,10 +135,13 @@ class JournalEntryFilterSet(BaseFilterSet): to_field_name='username', label='User (name)', ) + kind = django_filters.MultipleChoiceFilter( + choices=JournalEntryKindChoices + ) class Meta: model = JournalEntry - fields = ['id', 'assigned_object_type_id', 'assigned_object_id', 'created'] + fields = ['id', 'assigned_object_type_id', 'assigned_object_id', 'created', 'kind'] def search(self, queryset, name, value): if not value.strip(): diff --git a/netbox/extras/tests/test_filters.py b/netbox/extras/tests/test_filters.py index f4cfd2c88..5e1b0401d 100644 --- a/netbox/extras/tests/test_filters.py +++ b/netbox/extras/tests/test_filters.py @@ -5,7 +5,7 @@ from django.contrib.contenttypes.models import ContentType from django.test import TestCase from dcim.models import DeviceRole, Platform, Rack, Region, Site, SiteGroup -from extras.choices import ObjectChangeActionChoices +from extras.choices import JournalEntryKindChoices, ObjectChangeActionChoices from extras.filters import * from extras.models import * from ipam.models import IPAddress @@ -284,31 +284,37 @@ class JournalEntryTestCase(TestCase): JournalEntry( assigned_object=sites[0], created_by=users[0], + kind=JournalEntryKindChoices.KIND_INFO, comments='New journal entry' ), JournalEntry( assigned_object=sites[0], created_by=users[1], + kind=JournalEntryKindChoices.KIND_SUCCESS, comments='New journal entry' ), JournalEntry( assigned_object=sites[1], created_by=users[2], + kind=JournalEntryKindChoices.KIND_WARNING, comments='New journal entry' ), JournalEntry( assigned_object=racks[0], created_by=users[0], + kind=JournalEntryKindChoices.KIND_INFO, comments='New journal entry' ), JournalEntry( assigned_object=racks[0], created_by=users[1], + kind=JournalEntryKindChoices.KIND_SUCCESS, comments='New journal entry' ), JournalEntry( assigned_object=racks[1], created_by=users[2], + kind=JournalEntryKindChoices.KIND_WARNING, comments='New journal entry' ), ) @@ -338,6 +344,10 @@ class JournalEntryTestCase(TestCase): } self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) + def test_kind(self): + params = {'kind': [JournalEntryKindChoices.KIND_INFO, JournalEntryKindChoices.KIND_SUCCESS]} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4) + class ConfigContextTestCase(TestCase): queryset = ConfigContext.objects.all()