Skip to content

Commit 956d9d2

Browse files
pandafynemesifier
andcommitted
[feature] Switched to autocomplete filters
Co-authored-by: Federico Capoano <f.capoano@openwisp.io>
1 parent 7792c4b commit 956d9d2

5 files changed

Lines changed: 24 additions & 4 deletions

File tree

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ The ``settings.py`` of your project should contain the following:
481481
'openwisp_users',
482482
'openwisp_ipam',
483483
# admin
484+
'admin_auto_filters',
484485
'django.contrib.admin',
485486
# rest framework
486487
'rest_framework',
@@ -575,6 +576,7 @@ ensuring also that ``openwisp_ipam`` has been removed:
575576
'openwisp_users',
576577
# 'myipam', <-- replace without your app-name here
577578
# admin
579+
'admin_auto_filters',
578580
'django.contrib.admin',
579581
# rest framework
580582
'rest_framework',

openwisp_ipam/admin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .api.views import HostsSet
2323
from .base.forms import IpAddressImportForm
2424
from .base.models import CsvImportException
25+
from .filters import SubnetFilter, SubnetOrganizationFilter
2526

2627
Subnet = swapper.load_model('openwisp_ipam', 'Subnet')
2728
IpAddress = swapper.load_model('openwisp_ipam', 'IpAddress')
@@ -46,7 +47,7 @@ class SubnetAdmin(
4647
'created',
4748
'modified',
4849
]
49-
list_filter = [('organization', MultitenantOrgFilter)]
50+
list_filter = [MultitenantOrgFilter]
5051
autocomplete_fields = ['master_subnet']
5152
search_fields = ['subnet', 'name']
5253
list_select_related = ['organization', 'master_subnet']
@@ -218,7 +219,7 @@ class IpAddressAdmin(
218219
form = IpAddressAdminForm
219220
change_form_template = 'admin/openwisp-ipam/ip_address/change_form.html'
220221
list_display = ['ip_address', 'subnet', 'organization', 'created', 'modified']
221-
list_filter = ['subnet', ('subnet__organization', MultitenantOrgFilter)]
222+
list_filter = [SubnetOrganizationFilter, SubnetFilter]
222223
search_fields = ['ip_address']
223224
autocomplete_fields = ['subnet']
224225
multitenant_parent = 'subnet'

openwisp_ipam/filters.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.utils.translation import gettext_lazy as _
2+
from openwisp_users.multitenancy import MultitenantRelatedOrgFilter
3+
from swapper import load_model
4+
5+
Subnet = load_model('openwisp_ipam', 'Subnet')
6+
7+
8+
class SubnetFilter(MultitenantRelatedOrgFilter):
9+
field_name = 'subnet'
10+
parameter_name = 'subnet_id'
11+
title = _('subnet')
12+
13+
14+
class SubnetOrganizationFilter(MultitenantRelatedOrgFilter):
15+
parameter_name = 'subnet__organization'
16+
rel_model = Subnet

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openwisp-users @ https://github.com/openwisp/openwisp-users/tarball/3ec78ab47395b5aa1e4f27fd9670b57b6f0a3acb
1+
openwisp-users @ https://github.com/openwisp/openwisp-users/tarball/master
22
openwisp-utils[rest] @ https://github.com/openwisp/openwisp-utils/tarball/master
33
django>=3.0.0,<4.1.0
44
openpyxl~=3.0.9

tests/openwisp2/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
'django.contrib.sessions',
1414
'django.contrib.messages',
1515
'django.contrib.staticfiles',
16-
'openwisp_utils.admin_theme',
1716
'openwisp_users.accounts',
1817
# all-auth
1918
'django.contrib.sites',
@@ -26,7 +25,9 @@
2625
'openwisp_users',
2726
'openwisp_ipam',
2827
# admin
28+
'openwisp_utils.admin_theme',
2929
'django.contrib.admin',
30+
'admin_auto_filters',
3031
# rest framework
3132
'rest_framework',
3233
'rest_framework.authtoken',

0 commit comments

Comments
 (0)