Add a sortable Location column to the device page #547
-
|
Add a sortable Location column to the device page |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 17 replies
-
|
Is this a question or a feature request? In theory you could achieve this by "monkey patching" Not all users use geographic locations so taking up space for a column not everybody uses may not be a good default choice but it's definitely possible to show it. |
Beta Was this translation helpful? Give feedback.
-
|
I do not recommend modifying the source code of OpenWISP because the modification would get lost when you upgrade. Unless you want to maintain a separate fork and keep it up to date with master on your own, which is tedious. Instead I recommend to extend OpenWISP and modify only this small detail that you need. The following should work, but may need some adjustment. Upload a python file like the following to from django.apps import AppConfig
class ControllerExtensionConfig(AppConfig):
name = "openwisp2.controller_extension"
def ready(self, *args, **kwargs):
from openwisp_monitoring.device.admin import DeviceAdmin
def get_device_location(self, obj):
return obj.devicelocation.location if obj.devicelocation else None
get_device_location.short_description = "Location"
# Attach method dynamically
setattr(DeviceAdmin, "get_device_location", get_device_location)
# Insert into list_display before "ip"
list_columns = DeviceAdmin.list_display
ip_address_index = list_columns.index("ip")
list_columns.insert(ip_address_index + 1, "get_device_location")At the end of your INSTALLED_APPS.append("openwisp2.controller_extension.ControllerExtensionConfig")Restart the web application: You can use the # in the vars section of your ansible playbook YAML
vars:
openwisp2_extra_django_settings_instructions:
- INSTALLED_APPS.append("openwisp2.controller_extension.ControllerExtensionConfig")You could also upload the extra python file with ansible if you want to make this cleanly. If you manage it with ansible it should not be necessary to restart the application with If the above works, it should look like the following screenshot:
If it doesn't work let me know, I hope to help more people to understand how to extend/modify OpenWISP to fit their needs. A lot more things are possible by extending OpenWISP in this way, eg: listen to events and trigger custom actions. |
Beta Was this translation helpful? Give feedback.

I do not recommend modifying the source code of OpenWISP because the modification would get lost when you upgrade. Unless you want to maintain a separate fork and keep it up to date with master on your own, which is tedious.
Instead I recommend to extend OpenWISP and modify only this small detail that you need.
The following should work, but may need some adjustment.
Upload a python file like the following to
/opt/openwisp2/openwisp2/controller_extension.py: