From 83018b013fbebb1cf2730b8c4da2b7db1392b514 Mon Sep 17 00:00:00 2001 From: Holger Sielaff Date: Wed, 27 Aug 2025 10:18:39 +0200 Subject: [PATCH] set other lxc templates to not default on change --- proxmox/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/proxmox/models.py b/proxmox/models.py index 149d1ea..00aaf79 100644 --- a/proxmox/models.py +++ b/proxmox/models.py @@ -343,6 +343,11 @@ class LxcTemplate(ProxmoxAbstractModel, TaskAwareModelMixin): is_default_template = models.BooleanField(default=False, help_text='If true, this template will be used when creating new containers as default, or preselected') + def save(self, *args, **kwargs): + if self.is_default_template: + self.objects.filter(models.Q(is_default_template=True), ~models.Q(internal_id=self.pk)).update(is_default_template=False) + super().save(*args, **kwargs) + def __str__(self): return self.volid.split('/')[-1] @@ -352,3 +357,4 @@ class LxcTemplate(ProxmoxAbstractModel, TaskAwareModelMixin): @property def human_size(self): return human_size(self.size) +