Skip to content

Commit

Permalink
[feature] Switched to autocomplete filters
Browse files Browse the repository at this point in the history
Co-authored-by: Federico Capoano <[email protected]>
  • Loading branch information
pandafy and nemesifier committed Dec 6, 2022
1 parent 7792c4b commit 956d9d2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ The ``settings.py`` of your project should contain the following:
'openwisp_users',
'openwisp_ipam',
# admin
'admin_auto_filters',
'django.contrib.admin',
# rest framework
'rest_framework',
Expand Down Expand Up @@ -575,6 +576,7 @@ ensuring also that ``openwisp_ipam`` has been removed:
'openwisp_users',
# 'myipam', <-- replace without your app-name here
# admin
'admin_auto_filters',
'django.contrib.admin',
# rest framework
'rest_framework',
Expand Down
5 changes: 3 additions & 2 deletions openwisp_ipam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .api.views import HostsSet
from .base.forms import IpAddressImportForm
from .base.models import CsvImportException
from .filters import SubnetFilter, SubnetOrganizationFilter

Subnet = swapper.load_model('openwisp_ipam', 'Subnet')
IpAddress = swapper.load_model('openwisp_ipam', 'IpAddress')
Expand All @@ -46,7 +47,7 @@ class SubnetAdmin(
'created',
'modified',
]
list_filter = [('organization', MultitenantOrgFilter)]
list_filter = [MultitenantOrgFilter]
autocomplete_fields = ['master_subnet']
search_fields = ['subnet', 'name']
list_select_related = ['organization', 'master_subnet']
Expand Down Expand Up @@ -218,7 +219,7 @@ class IpAddressAdmin(
form = IpAddressAdminForm
change_form_template = 'admin/openwisp-ipam/ip_address/change_form.html'
list_display = ['ip_address', 'subnet', 'organization', 'created', 'modified']
list_filter = ['subnet', ('subnet__organization', MultitenantOrgFilter)]
list_filter = [SubnetOrganizationFilter, SubnetFilter]
search_fields = ['ip_address']
autocomplete_fields = ['subnet']
multitenant_parent = 'subnet'
Expand Down
16 changes: 16 additions & 0 deletions openwisp_ipam/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.utils.translation import gettext_lazy as _
from openwisp_users.multitenancy import MultitenantRelatedOrgFilter
from swapper import load_model

Subnet = load_model('openwisp_ipam', 'Subnet')


class SubnetFilter(MultitenantRelatedOrgFilter):
field_name = 'subnet'
parameter_name = 'subnet_id'
title = _('subnet')


class SubnetOrganizationFilter(MultitenantRelatedOrgFilter):
parameter_name = 'subnet__organization'
rel_model = Subnet
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openwisp-users @ https://github.com/openwisp/openwisp-users/tarball/3ec78ab47395b5aa1e4f27fd9670b57b6f0a3acb
openwisp-users @ https://github.com/openwisp/openwisp-users/tarball/master
openwisp-utils[rest] @ https://github.com/openwisp/openwisp-utils/tarball/master
django>=3.0.0,<4.1.0
openpyxl~=3.0.9
Expand Down
3 changes: 2 additions & 1 deletion tests/openwisp2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'openwisp_utils.admin_theme',
'openwisp_users.accounts',
# all-auth
'django.contrib.sites',
Expand All @@ -26,7 +25,9 @@
'openwisp_users',
'openwisp_ipam',
# admin
'openwisp_utils.admin_theme',
'django.contrib.admin',
'admin_auto_filters',
# rest framework
'rest_framework',
'rest_framework.authtoken',
Expand Down

0 comments on commit 956d9d2

Please sign in to comment.