From 0554f6427c706d6c393f6f1af548970eb9c672c3 Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Mon, 11 Apr 2022 15:20:47 +0200 Subject: [PATCH] Use named_id prefix "A-" for assets --- asset/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/asset/views.py b/asset/views.py index b4cf42e..a8a6df3 100644 --- a/asset/views.py +++ b/asset/views.py @@ -11,6 +11,8 @@ class AssetCreateView(CreateView): fields = ['named_id', 'description', 'quantity'] def form_valid(self, form): + if not form.instance.named_id.startswith('A-'): + form.instance.named_id = 'A-' + form.instance.named_id form.instance.changed_by = self.request.user form.instance.created_by = self.request.user return super().form_valid(form) @@ -19,8 +21,11 @@ class AssetCreateView(CreateView): class AssetUpdateView(UpdateView): model = Asset fields = ['named_id', 'description', 'quantity'] + success_url = '/asset/' def form_valid(self, form): + if not form.instance.named_id.startswith('A-'): + form.instance.named_id = 'A-' + form.instance.named_id form.instance.changed_by = self.request.user return super().form_valid(form)