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)