Re: [openwisp] How to apply a new template into multiple existing devices

22 views
Skip to first unread message

Federico Capoano

unread,
Mar 8, 2021, 9:41:01 PM3/8/21
to open...@googlegroups.com
Hi Pierre,

there was a similar question in the general chat today, at the moment we have to resort to the django shell for this.

The following example shows how to add multiple templates, in case anyone needs it. Here's how I do it:

I cd into the OpenWISP installation dir and activate the python virtual environment where the OpenWISP dependencies are installed:

cd /opt/openwisp2
source env/bin/activate
./manage.py shell_plus

Then I type in the interactive shell (shell_plus comes from django-extensions and preloads the DB models of the packages that are installed in the django project):

template1 = Template.objects.get(id="<TEMPLATE_UUID_HERE>")
template2 = Template.objects.get(id="<TEMPLATE_UUID_HERE>")

for device in Device.objects.all():
    device.config.templates.add(template1, template2)


The devices can be filtered as well with filter() in case you do not want to apply to all of them but only to a part.
For more info about how to use the django ORM (object relational mapper) to perform queries, see Making Queries in the django documentation.

I hope this helps, try and let us know.

Best regards
Federico Capoano
OpenWISP OÜ
Harjumaa, Tallinn, Sepapaja tn 6, 15551
VAT: EE101989729


On Mon, Mar 8, 2021 at 8:30 PM 'Pierre Untel' via OpenWISP <open...@googlegroups.com> wrote:
Hi, I have a lot of already registered devices that I want to apply a new template to them, what's the most efficient way to do this?

Thanks!

--
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/a7cb2744-0fbf-4f2f-8ba1-7cc4790ad1b4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages