diff --git a/asset/models.py b/asset/models.py
index f0df616..7e13c23 100644
--- a/asset/models.py
+++ b/asset/models.py
@@ -5,18 +5,21 @@ from django.contrib.auth import get_user_model
from container.models import Container
from django.urls import reverse
+
def get_sentinel_user():
return get_user_model().objects.get_or_create(username='deleted')[0]
+
class Asset(models.Model):
named_id = models.CharField(max_length=40, unique=True)
description = models.CharField(max_length=250, blank=True)
quantity = models.IntegerField(default=1)
created_ts = models.DateTimeField('datetime created', auto_now_add=True)
- created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user), related_name='created_assets')
+ created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user),
+ related_name='created_assets')
changed_ts = models.DateTimeField('datetime updated', auto_now=True)
- changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user), related_name='changed_assets')
+ changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user),
+ related_name='changed_assets')
def get_absolute_url(self):
return reverse('asset:detail', kwargs={'pk': self.pk})
-
diff --git a/asset/templates/asset/asset_confirm_delete.html b/asset/templates/asset/asset_confirm_delete.html
index bf4a076..3903065 100644
--- a/asset/templates/asset/asset_confirm_delete.html
+++ b/asset/templates/asset/asset_confirm_delete.html
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
-{% load statics %}
+{% load static %}
{% block content %}
Confirm Asset Delete
diff --git a/asset/templates/asset/asset_form.html b/asset/templates/asset/asset_form.html
index e2d48dd..dd5ef71 100644
--- a/asset/templates/asset/asset_form.html
+++ b/asset/templates/asset/asset_form.html
@@ -20,7 +20,7 @@
-->
-{{ form.as_p }}
+ {{ form.as_p }}
diff --git a/asset/templates/asset/asset_index.html b/asset/templates/asset/asset_index.html
deleted file mode 100644
index 5c91120..0000000
--- a/asset/templates/asset/asset_index.html
+++ /dev/null
@@ -1,32 +0,0 @@
-{% extends "base.html" %}
-{% load static %}
-
-{% block title %}Asset: {{ asset.named_id }}{% endblock %}
-
-{% block content %}
-
-
New Assets:
- {% if asset_list %}
-
- {% else %}
-
No new assets are available.
- {% endif %}
-
-
-
-
-
-
-{% endblock content %}
-
diff --git a/asset/templates/asset/asset_list.html b/asset/templates/asset/asset_list.html
new file mode 100644
index 0000000..73f6385
--- /dev/null
+++ b/asset/templates/asset/asset_list.html
@@ -0,0 +1,63 @@
+{% extends "base.html" %}
+{% load static %}
+
+{% block title %}Asset: {{ asset.named_id }}{% endblock %}
+
+{% block content %}
+
+
New Assets:
+ {% if asset_list %}
+
+
+ {% else %}
+
No new assets are available.
+ {% endif %}
+
+
+
+
+
+
+
+{% endblock content %}
+
diff --git a/asset/urls.py b/asset/urls.py
index c3abad9..c58cf87 100644
--- a/asset/urls.py
+++ b/asset/urls.py
@@ -1,14 +1,14 @@
from django.urls import path
from . import views
-from asset.views import AssetCreateView, AssetDeleteView, AssetUpdateView, AssetIndexView
+from asset.views import AssetCreateView, AssetDeleteView, AssetUpdateView, AssetListView
app_name = 'asset'
urlpatterns = [
- path('', AssetIndexView.as_view(), name='index'),
+ path('', AssetListView.as_view(), name='index'),
path('add/', AssetCreateView.as_view(), name='add'),
path('/', AssetUpdateView.as_view(), name='asset-update'),
path('/', AssetUpdateView.as_view(), name='detail'),
path('/save', views.asset_save, name='asset-save'),
- path('/delete/', AssetDeleteView.as_view(), name='asset-delete'),
+ path('/delete/', AssetDeleteView.as_view(), name='delete'),
]
diff --git a/asset/views.py b/asset/views.py
index 1885bdc..0c079db 100644
--- a/asset/views.py
+++ b/asset/views.py
@@ -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'))
-
diff --git a/container/urls.py b/container/urls.py
index b4917ca..e43b6cd 100644
--- a/container/urls.py
+++ b/container/urls.py
@@ -8,6 +8,7 @@ urlpatterns = [
path('/', views.DetailView.as_view(), name='detail'),
path('edit//', views.EditView.as_view(), name='edit'),
path('delete//', views.DeleteView.as_view(), name='delete'),
+ path('add/', views.AddView.as_view(), name='add'),
path('type/', views.TypeIndexView.as_view(), name='container_type_index'),
path('type//', views.TypeDetailView.as_view(), name='container_type_detail'),
]
diff --git a/container/views.py b/container/views.py
index 3b9016f..fef7737 100644
--- a/container/views.py
+++ b/container/views.py
@@ -38,3 +38,5 @@ class EditView(generic.DetailView):
class DeleteView(generic.DetailView):
model = Container
+class AddView(generic.DetailView):
+ model = Container