Use named_id prefix "A-" for assets

This commit is contained in:
Dirk Jahnke 2022-04-11 15:20:47 +02:00
parent 6aadef827e
commit 0554f6427c
1 changed files with 5 additions and 0 deletions

View File

@ -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)