From 056317a3408e89fe97003dbb0d7b38c8d9a861ea Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Mon, 11 Apr 2022 14:23:07 +0200 Subject: [PATCH] Container use prefix "C-" for named_id --- container/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/container/views.py b/container/views.py index a1eae54..b57af54 100644 --- a/container/views.py +++ b/container/views.py @@ -27,6 +27,8 @@ class ContainerCreateView(LoginRequiredMixin, generic.CreateView): fields = ['named_id', 'description', 'color', 'container_type'] def form_valid(self, form): + if not form.instance.named_id.startswith('C-'): + form.instance.named_id = 'C-' + form.instance.named_id form.instance.changed_by = self.request.user form.instance.created_by = self.request.user return super().form_valid(form) @@ -53,8 +55,11 @@ class ContainerUpdateView(LoginRequiredMixin, generic.UpdateView): model = Container # template_name = 'container/detail.html' fields = ['named_id', 'description', 'color', 'container_type'] + success_url = "/container/" def form_valid(self, form): + if not form.instance.named_id.startswith('C-'): + form.instance.named_id = 'C-' + form.instance.named_id form.instance.changed_by = self.request.user return super().form_valid(form)