Need to add one more field template information in device table of openwisp UI

39 views
Skip to first unread message

Amit Goyal

unread,
Aug 29, 2019, 5:18:58 AM8/29/19
to OpenWISP
Hi Openwisp Team 

I am very new to Django Frame work and don't know complete details of openwisp django frame work.

I need to add one more field in device table of Openwisp UI . 

New Field-: Template linked to Device 
Changes expecting -: 
1-: Query fetching device table information 
2-: UI change to display new field template in device table 

Can someone let me know where all I need to make change in openwisp-controller 3.2 to implement this requirement 

Device Table-: Template new field to be added.


openwisp.jpg


openwisp.jpg

Noumbissi Valere

unread,
Aug 29, 2019, 6:41:39 AM8/29/19
to open...@googlegroups.com
Hello Amit,

The relationship between Device and Template is found in the Config model.
You can add a custom  modelAdmin field to the DeviceAdmin found in openwisp_controller.config.admin.py file.
once you've created your custom field, you can then add it to the list_display by appending it to the DeviceAdmin.list_display. something like this,

def template_field(self, obj):
template_names = []
if obj:
config = Config.objects.get(device=obj)
templates = config.templates.all()
for template in templates:
template_names.append(template.name)
return ",".join(template_names)
return

template_field.short_description = "Templates"

DeviceAdmin.list_display.append('template_field')

to achieve something like this, 



--
You received this message because you are subscribed to the Google Groups "OpenWISP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openwisp+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openwisp/6b65dae6-cc82-4c78-a296-16388097bd55%40googlegroups.com.
Screenshot from 2019-08-29 11-39-56.png

Amit Goyal

unread,
Sep 4, 2019, 2:52:13 AM9/4/19
to OpenWISP
Hi Noumbissi

Thanks for your help.


I have updated  /usr/src/app/openwisp_controller/config/admin.py  inside openwisp container as below but changes are not reflecting on UI side even after openwisp restart.

//Added template_field in DeviceAdmin

class DeviceAdmin(MultitenantAdminMixin, AbstractDeviceAdmin):
    inlines = [ConfigInline]
    list_filter = [('organization', MultitenantOrgFilter),
                   'config__backend',
                   ('config__templates', MultitenantRelatedOrgFilter),
                   'config__status',
                   'created','template_field']

//add it to list_display

 def template_field(self, obj):
        template_names = []
        if obj:
            config = Config.objects.get(device=obj)
            templates = config.templates.all()
            for template in templates:
                template_names.append(template.name)
            return ",".join(template_names)
        return

    template_field.short_description = "Templates"

DeviceAdmin.list_display.append('template_field')


Please let me know what need to be done to get it displayed at UI side . 
To unsubscribe from this group and stop receiving emails from it, send an email to open...@googlegroups.com.

Noumbissi Valere

unread,
Sep 4, 2019, 3:06:54 AM9/4/19
to open...@googlegroups.com
Hello Amit,

did the openwisp-controller restart without any errors? and is the normal flow of adding new devices working without any errors? if they are, then it should work. 
please ensure the method is in the class and that openwisp-controller restarts with the added changes.

To unsubscribe from this group and stop receiving emails from it, send an email to openwisp+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openwisp/07d8e449-1445-4aeb-89f9-1bcac3e2e2ee%40googlegroups.com.

Amit Goyal

unread,
Sep 4, 2019, 8:21:32 AM9/4/19
to OpenWISP
Hello Noumbissi

Sorry by mistake I have added one more text , that's why it was not working .
removed extra text  and update code. It's working now. 

Thanks a lot for your help ! 

A Stanley

unread,
Sep 4, 2019, 8:23:16 AM9/4/19
to open...@googlegroups.com
How did you add the file in the container?   Did you rebuild the container?

Noumbissi Valere

unread,
Sep 4, 2019, 8:24:06 AM9/4/19
to open...@googlegroups.com
You are welcome Amit, 
Glad I could help 🙂. 

To unsubscribe from this group and stop receiving emails from it, send an email to openwisp+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openwisp/922a1f60-7234-4b04-ac03-fd13cd25e9a1%40googlegroups.com.

Amit Goyal

unread,
Sep 6, 2019, 2:34:13 AM9/6/19
to OpenWISP
Hi

For testing purpose ,  I made direct changes in container.
In container , following file need to be changed.

/usr/local/lib/python3.6/site-packages/openwisp_controller/config/admin.py

--
You received this message because you are subscribed to the Google Groups "OpenWISP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open...@googlegroups.com.

TAMALAMPUDI VIJAYA KUMAR REDDY (N170066)

unread,
Sep 7, 2019, 12:04:41 PM9/7/19
to open...@googlegroups.com
Hello sir
I want to contribute to openwisp i know python but i dont have any experience in software development how can i start contributing


To unsubscribe from this group and stop receiving emails from it, send an email to openwisp+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openwisp/c3c1c31e-e009-4250-99f0-698967cf6c71%40googlegroups.com.


--
 yours sincerely,
T.Vijay Kumar Reddy,
N170066,
PUC-2,
RGUKT ,Nuzvid,.
ph;7901516156.

Noumbissi Valere

unread,
Sep 7, 2019, 3:31:45 PM9/7/19
to open...@googlegroups.com
Hello Reddy,

Your are welcome to OpenWISP. 
You can start off by reading our contribution guidelines from here; http://openwisp.io/docs/developer/contributing.html .
When you are done, you can move on to pick any issue from our contribution board. This can be found here;  https://github.com/orgs/openwisp/projects/3
Since you are versed with Python, i will advice you to start with the To do (python & django) section. 
If you have any questions, you can post them here or on the gitter channel.

Happy hacking 🙂

Reply all
Reply to author
Forward
0 new messages