|
1 |
| -import django_filters |
2 | 1 | import logging
|
| 2 | + |
3 | 3 | from core.models import ObjectChange
|
4 | 4 | from core.tables import ObjectChangeTable
|
5 | 5 | from django.contrib.contenttypes.models import ContentType
|
6 |
| -from django.contrib.postgres.fields import ArrayField |
7 |
| -from django.db.models import JSONField, Q |
| 6 | +from django.db.models import Q |
8 | 7 | from django.shortcuts import get_object_or_404, render
|
9 | 8 | from django.urls import reverse
|
10 | 9 | from django.utils.translation import gettext_lazy as _
|
|
13 | 12 | from extras.forms import JournalEntryForm
|
14 | 13 | from extras.models import JournalEntry
|
15 | 14 | from extras.tables import JournalEntryTable
|
16 |
| -from netbox.filtersets import BaseFilterSet |
17 | 15 | from netbox.forms import NetBoxModelBulkEditForm, NetBoxModelFilterSetForm
|
18 | 16 | from netbox.views import generic
|
19 | 17 | from netbox.views.generic.mixins import TableMixin
|
20 | 18 | from utilities.forms import ConfirmationForm
|
21 | 19 | from utilities.htmx import htmx_partial
|
22 |
| -from utilities.views import ( |
23 |
| - ConditionalLoginRequiredMixin, |
24 |
| - ViewTab, |
25 |
| - get_viewname, |
26 |
| - register_model_view, |
27 |
| -) |
| 20 | +from utilities.views import ConditionalLoginRequiredMixin, ViewTab, get_viewname, register_model_view |
28 | 21 |
|
| 22 | +from netbox_custom_objects.filtersets import get_filterset_class |
29 | 23 | from netbox_custom_objects.tables import CustomObjectTable
|
30 |
| - |
31 | 24 | from . import field_types, filtersets, forms, tables
|
32 | 25 | from .models import CustomObject, CustomObjectType, CustomObjectTypeField
|
33 | 26 |
|
@@ -324,44 +317,7 @@ def get_queryset(self, request):
|
324 | 317 | return model.objects.all()
|
325 | 318 |
|
326 | 319 | def get_filterset(self):
|
327 |
| - model = self.queryset.model |
328 |
| - fields = [field.name for field in model._meta.fields] |
329 |
| - |
330 |
| - meta = type( |
331 |
| - "Meta", |
332 |
| - (), |
333 |
| - { |
334 |
| - "model": model, |
335 |
| - "fields": fields, |
336 |
| - # TODO: overrides should come from FieldType |
337 |
| - # These are placeholders; should use different logic |
338 |
| - "filter_overrides": { |
339 |
| - JSONField: { |
340 |
| - "filter_class": django_filters.CharFilter, |
341 |
| - "extra": lambda f: { |
342 |
| - "lookup_expr": "icontains", |
343 |
| - }, |
344 |
| - }, |
345 |
| - ArrayField: { |
346 |
| - "filter_class": django_filters.CharFilter, |
347 |
| - "extra": lambda f: { |
348 |
| - "lookup_expr": "icontains", |
349 |
| - }, |
350 |
| - }, |
351 |
| - }, |
352 |
| - }, |
353 |
| - ) |
354 |
| - |
355 |
| - attrs = { |
356 |
| - "Meta": meta, |
357 |
| - "__module__": "database.filtersets", |
358 |
| - } |
359 |
| - |
360 |
| - return type( |
361 |
| - f"{model._meta.object_name}FilterSet", |
362 |
| - (BaseFilterSet,), # TODO: Should be a NetBoxModelFilterSet |
363 |
| - attrs, |
364 |
| - ) |
| 320 | + return get_filterset_class(self.queryset.model) |
365 | 321 |
|
366 | 322 | def get_filterset_form(self):
|
367 | 323 | model = self.queryset.model
|
|
0 commit comments