Container use prefix "C-" for named_id

This commit is contained in:
Dirk Jahnke 2022-04-11 14:23:07 +02:00
parent 5cf49b7d47
commit 056317a340
1 changed files with 5 additions and 0 deletions

View File

@ -27,6 +27,8 @@ class ContainerCreateView(LoginRequiredMixin, generic.CreateView):
fields = ['named_id', 'description', 'color', 'container_type'] fields = ['named_id', 'description', 'color', 'container_type']
def form_valid(self, form): 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.changed_by = self.request.user
form.instance.created_by = self.request.user form.instance.created_by = self.request.user
return super().form_valid(form) return super().form_valid(form)
@ -53,8 +55,11 @@ class ContainerUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Container model = Container
# template_name = 'container/detail.html' # template_name = 'container/detail.html'
fields = ['named_id', 'description', 'color', 'container_type'] fields = ['named_id', 'description', 'color', 'container_type']
success_url = "/container/"
def form_valid(self, form): 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.changed_by = self.request.user
return super().form_valid(form) return super().form_valid(form)