diff --git a/asset/__init__.py b/asset/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/asset/admin.py b/asset/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/asset/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/asset/apps.py b/asset/apps.py new file mode 100644 index 0000000..46953e7 --- /dev/null +++ b/asset/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AssetConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'asset' diff --git a/asset/migrations/0001_initial.py b/asset/migrations/0001_initial.py new file mode 100644 index 0000000..a1f8be8 --- /dev/null +++ b/asset/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.12 on 2022-03-10 16:09 + +import asset.models +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Asset', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=40)), + ('description', models.CharField(blank=True, max_length=250)), + ('quantity', models.IntegerField(default=1)), + ('created_ts', models.DateTimeField(auto_now_add=True, verbose_name='datetime created')), + ('changed_ts', models.DateTimeField(auto_now=True, verbose_name='datetime updated')), + ('changed_by', models.ForeignKey(on_delete=models.SET(asset.models.get_sentinel_user), related_name='changed_assets', to=settings.AUTH_USER_MODEL)), + ('created_by', models.ForeignKey(on_delete=models.SET(asset.models.get_sentinel_user), related_name='created_assets', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/asset/migrations/0002_auto_20220310_1620.py b/asset/migrations/0002_auto_20220310_1620.py new file mode 100644 index 0000000..a5d5340 --- /dev/null +++ b/asset/migrations/0002_auto_20220310_1620.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.12 on 2022-03-10 16:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('asset', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='asset', + name='name', + ), + migrations.AddField( + model_name='asset', + name='named_id', + field=models.CharField(default='defval', max_length=40, unique=True), + preserve_default=False, + ), + ] diff --git a/asset/migrations/__init__.py b/asset/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/asset/models.py b/asset/models.py new file mode 100644 index 0000000..eb0c85c --- /dev/null +++ b/asset/models.py @@ -0,0 +1,18 @@ +from django.db import models +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 + +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') + 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') + diff --git a/asset/templates/asset/asset_confirm_delete.html b/asset/templates/asset/asset_confirm_delete.html new file mode 100644 index 0000000..bf4a076 --- /dev/null +++ b/asset/templates/asset/asset_confirm_delete.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} +{% load statics %} + +{% block content %} +

Confirm Asset Delete

+{% endblock %} diff --git a/asset/templates/asset/asset_form.html b/asset/templates/asset/asset_form.html new file mode 100644 index 0000000..e7713d4 --- /dev/null +++ b/asset/templates/asset/asset_form.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} +{% load statics %} + +{% block content %} +

Form for Asset

+{% endblock %} diff --git a/asset/templates/asset/asset_index.html b/asset/templates/asset/asset_index.html new file mode 100644 index 0000000..5cbccd0 --- /dev/null +++ b/asset/templates/asset/asset_index.html @@ -0,0 +1,22 @@ +{% 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/tests.py b/asset/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/asset/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/asset/urls.py b/asset/urls.py new file mode 100644 index 0000000..38c039e --- /dev/null +++ b/asset/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from asset.views import AssetCreateView, AssetDeleteView, AssetUpdateView, AssetIndexView + +app_name = 'asset' +urlpatterns = [ + path('', AssetIndexView.as_view(), name='index'), + path('add/', AssetCreateView.as_view(), name='asset-add'), + path('/', AssetUpdateView.as_view(), name='asset-update'), + path('/delete/', AssetDeleteView.as_view(), name='asset-delete'), +] + diff --git a/asset/views.py b/asset/views.py new file mode 100644 index 0000000..de397f4 --- /dev/null +++ b/asset/views.py @@ -0,0 +1,25 @@ +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 + +class AssetCreateView(CreateView): + model = Asset + #fields = ['name'] + +class AssetUpdateView(UpdateView): + model = Asset + #fields = ['name'] + +class AssetDeleteView(DeleteView): + model = Asset + success_url = reverse_lazy('asset-list') + +class AssetIndexView(generic.ListView): + template_name = 'asset/asset_index.html' + context_object_name = 'asset_list' + + def get_queryset(self): + # Return the last 20 created containers + return Asset.objects.order_by('-created_ts')[:20] + diff --git a/homelog/settings.py b/homelog/settings.py index 368dc60..f98bfcb 100644 --- a/homelog/settings.py +++ b/homelog/settings.py @@ -31,6 +31,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'asset.apps.AssetConfig', 'container.apps.ContainerConfig', 'django.contrib.admin', 'django.contrib.auth', diff --git a/homelog/templates/homelog/home.html b/homelog/templates/homelog/home.html index 31a7027..7f83bc1 100644 --- a/homelog/templates/homelog/home.html +++ b/homelog/templates/homelog/home.html @@ -6,6 +6,7 @@

This is HOME

Container Types
Container
+Assets
{% endblock %} diff --git a/homelog/urls.py b/homelog/urls.py index 7b5904e..f40a5df 100644 --- a/homelog/urls.py +++ b/homelog/urls.py @@ -26,5 +26,6 @@ urlpatterns = [ path('home/', TemplateView.as_view(template_name="homelog/home.html"), name='home'), path('about/', TemplateView.as_view(template_name="homelog/about.html"), name='about'), path('container/', include('container.urls')), + path('asset/', include('asset.urls')), path('admin/', admin.site.urls), ]