From fa2b83a63a24c925f6d27179ea8e6b70ad487554 Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Wed, 16 Mar 2022 14:13:20 +0100 Subject: [PATCH] Added asset edit/save --- asset/templates/asset/asset_form.html | 23 ++++++++++++++++++++--- asset/urls.py | 2 ++ asset/views.py | 9 +++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/asset/templates/asset/asset_form.html b/asset/templates/asset/asset_form.html index 2dff386..dccae0a 100644 --- a/asset/templates/asset/asset_form.html +++ b/asset/templates/asset/asset_form.html @@ -1,6 +1,23 @@ -{% extends 'base.html' %} +{% extends "base.html" %} {% load static %} +{% block title %}Edit Asset: {{ asset.named_id }}{% endblock %} + {% block content %} -

Form for Asset

-{% endblock %} +
+
+{% csrf_token %} +
+
+ +

Asset: {{ asset.named_id }}

+ {% if error_message %}

{{ error_message }}

{% endif %} +
+
+
+
+
+
+ +
+{% endblock content %} diff --git a/asset/urls.py b/asset/urls.py index 38c039e..124fd33 100644 --- a/asset/urls.py +++ b/asset/urls.py @@ -1,4 +1,5 @@ from django.urls import path +from . import views from asset.views import AssetCreateView, AssetDeleteView, AssetUpdateView, AssetIndexView app_name = 'asset' @@ -6,6 +7,7 @@ urlpatterns = [ path('', AssetIndexView.as_view(), name='index'), path('add/', AssetCreateView.as_view(), name='asset-add'), path('/', AssetUpdateView.as_view(), name='asset-update'), + path('/save', views.asset_save, name='asset-save'), path('/delete/', AssetDeleteView.as_view(), name='asset-delete'), ] diff --git a/asset/views.py b/asset/views.py index baca53e..d0d99d9 100644 --- a/asset/views.py +++ b/asset/views.py @@ -2,6 +2,8 @@ from django.urls import reverse_lazy from django.views.generic.edit import CreateView, DeleteView, UpdateView from django.views import generic from asset.models import Asset +from django.shortcuts import get_object_or_404, reverse +from django.http import HttpResponse, HttpResponseRedirect class AssetCreateView(CreateView): model = Asset @@ -23,3 +25,10 @@ class AssetIndexView(generic.ListView): # Return the last 20 created containers return Asset.objects.order_by('-created_ts')[:20] +def asset_save(request, asset_id): + asset = get_object_or_404(Asset, pk=asset_id) + asset.description = request.POST['description'] + asset.quantity = request.POST['quantity'] + asset.save(); + return HttpResponseRedirect(reverse('asset:index')) +