diff --git a/asset/models.py b/asset/models.py index eb0c85c..f0df616 100644 --- a/asset/models.py +++ b/asset/models.py @@ -3,6 +3,7 @@ from django.conf import settings from django.contrib.auth import get_user_model # from django.contrib.auth.models import User 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] @@ -16,3 +17,6 @@ class Asset(models.Model): 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') + def get_absolute_url(self): + return reverse('asset:detail', kwargs={'pk': self.pk}) + diff --git a/asset/templates/asset/asset_form.html b/asset/templates/asset/asset_form.html index dccae0a..e2d48dd 100644 --- a/asset/templates/asset/asset_form.html +++ b/asset/templates/asset/asset_form.html @@ -5,18 +5,23 @@ {% block content %}
-
+ {% csrf_token %} + +{{ form.as_p }} +
diff --git a/asset/templates/asset/asset_index.html b/asset/templates/asset/asset_index.html index 300ce5e..5c91120 100644 --- a/asset/templates/asset/asset_index.html +++ b/asset/templates/asset/asset_index.html @@ -16,7 +16,17 @@

No new assets are available.

{% endif %} -
+ +
+ + + +
+ +
{% endblock content %} diff --git a/asset/urls.py b/asset/urls.py index 124fd33..c3abad9 100644 --- a/asset/urls.py +++ b/asset/urls.py @@ -5,8 +5,9 @@ from asset.views import AssetCreateView, AssetDeleteView, AssetUpdateView, Asset app_name = 'asset' urlpatterns = [ path('', AssetIndexView.as_view(), name='index'), - path('add/', AssetCreateView.as_view(), name='asset-add'), + 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'), ] diff --git a/asset/views.py b/asset/views.py index d0d99d9..1885bdc 100644 --- a/asset/views.py +++ b/asset/views.py @@ -9,10 +9,19 @@ class AssetCreateView(CreateView): model = Asset fields = ['named_id', 'description', 'quantity'] + def form_valid(self, form): + form.instance.changed_by = self.request.user + form.instance.created_by = self.request.user + return super().form_valid(form) + class AssetUpdateView(UpdateView): model = Asset fields = ['named_id', 'description', 'quantity'] + def form_valid(self, form): + form.instance.changed_by = self.request.user + return super().form_valid(form) + class AssetDeleteView(DeleteView): model = Asset success_url = reverse_lazy('asset-index')