Improved asset list (was index)

This commit is contained in:
2022-03-17 07:21:38 +01:00
parent 5f2b2c92ab
commit 92176158bd
9 changed files with 89 additions and 44 deletions

View File

@@ -5,6 +5,7 @@ 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
fields = ['named_id', 'description', 'quantity']
@@ -14,6 +15,7 @@ class AssetCreateView(CreateView):
form.instance.created_by = self.request.user
return super().form_valid(form)
class AssetUpdateView(UpdateView):
model = Asset
fields = ['named_id', 'description', 'quantity']
@@ -22,17 +24,24 @@ class AssetUpdateView(UpdateView):
form.instance.changed_by = self.request.user
return super().form_valid(form)
class AssetDeleteView(DeleteView):
model = Asset
success_url = reverse_lazy('asset-index')
class AssetIndexView(generic.ListView):
template_name = 'asset/asset_index.html'
context_object_name = 'asset_list'
class AssetListView(generic.ListView):
template_name = 'asset/asset_list.html'
context_object_name = 'asset_list'
model = Asset
paginate_by = 20
"""
def get_queryset(self):
# 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)
@@ -40,4 +49,3 @@ def asset_save(request, asset_id):
asset.quantity = request.POST['quantity']
asset.save();
return HttpResponseRedirect(reverse('asset:index'))