-
|
I've just started looking at config templates to see how they can be used. I'm trying to change the config template in bulk for a group of devices using >>> Device.objects.get(id=66).config_template_id
1
>>> Device.objects.get(id=66).config_template_id=2
>>> Device.objects.get(id=66).full_clean()
>>> Device.objects.get(id=66).save()
Updating denormalized values for <class 'dcim.models.cables.CableTermination'>._device
Updated 1 rows
>>> Device.objects.get(id=66).config_template_id
1>>> ConfigTemplate.objects.get(id=1)
<ConfigTemplate: snmp>
>>> ConfigTemplate.objects.get(id=2)
<ConfigTemplate: ping>
>>> Device.objects.get(id=66).config_template
<ConfigTemplate: snmp>
>>> Device.objects.get(id=66).config_template = ConfigTemplate.objects.get(id=2)
>>> Device.objects.get(id=66).full_clean()
>>> Device.objects.get(id=66).save()
Updating denormalized values for <class 'dcim.models.cables.CableTermination'>._device
Updated 1 rows
>>> Device.objects.get(id=66).config_template
<ConfigTemplate: snmp> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
You can't just keep re-fetching the object from the database - each will be a fresh object and won't have any changes applied. For example, Instead: load the object and assign it to a variable, mutate that object, and then save it. Untested: (The "snapshot" is required if you want change logging to work) |
Beta Was this translation helpful? Give feedback.
You can't just keep re-fetching the object from the database - each will be a fresh object and won't have any changes applied. For example,
Device.objects.get(id=66).save()will fetch a fresh copy of the object from the database, and then immediately save it (without any changes). The objects you had previously loaded, but not saved into any variable, will be garbage-collected.Instead: load the object and assign it to a variable, mutate that object, and then save it. Untested:
(The "snapshot" is required if you want change logging to work)