diff --git a/.gitignore b/.gitignore index 270553b..0dd8805 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,34 @@ db.sqlite3 - +*.log +*.pot +__pycache__ +media +*.bak +.idea +*.py[cod] +*$py.class +*.egg +*.manifest +pip-log.txt +pip-delete-this-directory.txt +.coverage +.cache +.tox +htmlcov +.hypothesis +.python-version +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +/site +.mypy_cache/ +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history diff --git a/container/admin.py b/container/admin.py index 8c38f3f..b4723c1 100644 --- a/container/admin.py +++ b/container/admin.py @@ -1,3 +1,8 @@ from django.contrib import admin -# Register your models here. +from .models import Container +from .models import ContainerType + +admin.site.register(ContainerType) +admin.site.register(Container) + diff --git a/container/migrations/0001_initial.py b/container/migrations/0001_initial.py new file mode 100644 index 0000000..70e86dd --- /dev/null +++ b/container/migrations/0001_initial.py @@ -0,0 +1,52 @@ +# Generated by Django 3.2.12 on 2022-03-09 14:12 + +import container.models +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='ContainerType', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('named_id', models.CharField(max_length=40, unique=True)), + ('description', models.CharField(max_length=200)), + ('width', models.IntegerField(verbose_name='width in mm')), + ('height', models.IntegerField(verbose_name='height in mm')), + ('length', models.IntegerField(verbose_name='length in mm')), + ('inner_width', models.IntegerField(verbose_name='inner width in mm')), + ('inner_height', models.IntegerField(verbose_name='inner height in mm')), + ('inner_length', models.IntegerField(verbose_name='inner length in mm')), + ('has_cover', models.BooleanField(verbose_name='container has a cover')), + ('contains_container', models.BooleanField(verbose_name='container can bear container')), + ('created_date', models.DateTimeField(verbose_name='datetime created')), + ('changed_date', models.DateTimeField(verbose_name='datetime updated')), + ('changed_by', models.ForeignKey(on_delete=models.SET(container.models.get_sentinel_user), related_name='changed_container_types', to=settings.AUTH_USER_MODEL)), + ('created_by', models.ForeignKey(on_delete=models.SET(container.models.get_sentinel_user), related_name='created_container_types', to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.CreateModel( + name='Container', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('named_id', models.CharField(max_length=40)), + ('color', models.CharField(max_length=60)), + ('description', models.CharField(max_length=200)), + ('created_date', models.DateTimeField(verbose_name='datetime created')), + ('changed_date', models.DateTimeField(verbose_name='datetime updated')), + ('changed_by', models.ForeignKey(on_delete=models.SET(container.models.get_sentinel_user), related_name='changed_container', to=settings.AUTH_USER_MODEL)), + ('container_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='container.containertype')), + ('created_by', models.ForeignKey(on_delete=models.SET(container.models.get_sentinel_user), related_name='created_container', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/container/migrations/0002_auto_20220309_1419.py b/container/migrations/0002_auto_20220309_1419.py new file mode 100644 index 0000000..be66cc9 --- /dev/null +++ b/container/migrations/0002_auto_20220309_1419.py @@ -0,0 +1,58 @@ +# Generated by Django 3.2.12 on 2022-03-09 14:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('container', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='container', + name='changed_date', + field=models.DateTimeField(auto_now=True, verbose_name='datetime updated'), + ), + migrations.AlterField( + model_name='container', + name='color', + field=models.CharField(blank=True, max_length=60), + ), + migrations.AlterField( + model_name='container', + name='created_date', + field=models.DateTimeField(auto_now_add=True, verbose_name='datetime created'), + ), + migrations.AlterField( + model_name='container', + name='description', + field=models.CharField(blank=True, max_length=200), + ), + migrations.AlterField( + model_name='containertype', + name='changed_date', + field=models.DateTimeField(auto_now=True, verbose_name='datetime updated'), + ), + migrations.AlterField( + model_name='containertype', + name='created_date', + field=models.DateTimeField(auto_now_add=True, verbose_name='datetime created'), + ), + migrations.AlterField( + model_name='containertype', + name='inner_height', + field=models.IntegerField(null=True, verbose_name='inner height in mm'), + ), + migrations.AlterField( + model_name='containertype', + name='inner_length', + field=models.IntegerField(null=True, verbose_name='inner length in mm'), + ), + migrations.AlterField( + model_name='containertype', + name='inner_width', + field=models.IntegerField(null=True, verbose_name='inner width in mm'), + ), + ] diff --git a/container/migrations/0003_auto_20220309_1422.py b/container/migrations/0003_auto_20220309_1422.py new file mode 100644 index 0000000..653326e --- /dev/null +++ b/container/migrations/0003_auto_20220309_1422.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.12 on 2022-03-09 14:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('container', '0002_auto_20220309_1419'), + ] + + operations = [ + migrations.AlterField( + model_name='containertype', + name='inner_height', + field=models.IntegerField(blank=True, null=True, verbose_name='inner height in mm'), + ), + migrations.AlterField( + model_name='containertype', + name='inner_length', + field=models.IntegerField(blank=True, null=True, verbose_name='inner length in mm'), + ), + migrations.AlterField( + model_name='containertype', + name='inner_width', + field=models.IntegerField(blank=True, null=True, verbose_name='inner width in mm'), + ), + ] diff --git a/container/migrations/0004_auto_20220309_1445.py b/container/migrations/0004_auto_20220309_1445.py new file mode 100644 index 0000000..c26a99d --- /dev/null +++ b/container/migrations/0004_auto_20220309_1445.py @@ -0,0 +1,33 @@ +# Generated by Django 3.2.12 on 2022-03-09 14:45 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('container', '0003_auto_20220309_1422'), + ] + + operations = [ + migrations.RenameField( + model_name='container', + old_name='changed_date', + new_name='changed_ts', + ), + migrations.RenameField( + model_name='container', + old_name='created_date', + new_name='created_ts', + ), + migrations.RenameField( + model_name='containertype', + old_name='changed_date', + new_name='changed_ts', + ), + migrations.RenameField( + model_name='containertype', + old_name='created_date', + new_name='created_ts', + ), + ] diff --git a/container/models.py b/container/models.py index 71a8362..3812443 100644 --- a/container/models.py +++ b/container/models.py @@ -1,3 +1,33 @@ from django.db import models +from django.conf import settings +from django.contrib.auth import get_user_model + +def get_sentinel_user(): + return get_user_model().objects.get_or_create(username='deleted')[0] + +class ContainerType(models.Model): + named_id = models.CharField(max_length=40, unique=True) + description = models.CharField(max_length=200) + width = models.IntegerField('width in mm') + height = models.IntegerField('height in mm') + length = models.IntegerField('length in mm') + inner_width = models.IntegerField('inner width in mm', blank=True, null=True) + inner_height = models.IntegerField('inner height in mm', blank=True, null=True) + inner_length = models.IntegerField('inner length in mm', blank=True, null=True) + has_cover = models.BooleanField('container has a cover') + contains_container = models.BooleanField('container can bear container') + 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_container_types') + 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_container_types') + +class Container(models.Model): + named_id = models.CharField(max_length=40) + container_type = models.ForeignKey(ContainerType, on_delete=models.CASCADE) + color = models.CharField(max_length=60, blank=True) + description = models.CharField(max_length=200, blank=True) + 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_container') + 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_container') -# Create your models here. diff --git a/container/templates/container/container_details.html b/container/templates/container/container_details.html new file mode 100644 index 0000000..e4d957e --- /dev/null +++ b/container/templates/container/container_details.html @@ -0,0 +1,4 @@ +

Container: {{ container.named_id }}

+
{{ container.description }}
+
Color: {{ container.color }}
+
Container Type: {{ container.container_type.named_id }}
diff --git a/container/templates/container/container_type_details.html b/container/templates/container/container_type_details.html new file mode 100644 index 0000000..0ca9326 --- /dev/null +++ b/container/templates/container/container_type_details.html @@ -0,0 +1,8 @@ +

Container: {{ container_type.named_id }}

+
{{ container_type.description }}
+ + + + + +
Width:{{ container_type.width }} mmInner Width:{{ container_type.inner_width }} mm
Length:{{ container_type.length }} mmInner Length:{{ container_type.inner_length }} mm
Height:{{ container_type.height }} mmInner Height:{{ container_type.inner_height }} mm
Has Cover:{% if container_type.has_cover %} yes {% else %} no {% endif %}Can hold Containers:{% if container_type.contains_container %} yes {% else %} no {% endif %}
diff --git a/container/templates/container/index.html b/container/templates/container/index.html new file mode 100644 index 0000000..d0ee396 --- /dev/null +++ b/container/templates/container/index.html @@ -0,0 +1,24 @@ +
+
New Container:
+{% if container_list %} + +{% else %} +

No container are available.

+{% endif %} +
+
+
New Container Types:
+{% if container_type_list %} + +{% else %} +

No container types are available.

+{% endif %} +
diff --git a/container/urls.py b/container/urls.py index 4c9189f..741186c 100644 --- a/container/urls.py +++ b/container/urls.py @@ -4,5 +4,8 @@ from . import views urlpatterns = [ path('', views.index, name='index'), + path('/', views.container_details, name='container_details'), + path('type//', views.container_type_details, name='container_type_details'), + # path('type//', views.container_type_details, name='container_type_details'), ] diff --git a/container/views.py b/container/views.py index 94aa362..070f6c3 100644 --- a/container/views.py +++ b/container/views.py @@ -1,7 +1,28 @@ from django.shortcuts import render from django.http import HttpResponse +from django.template import loader +from django.http import Http404 +from .models import Container, ContainerType def index(request): - return HttpResponse("Hello, world. You're at the container index.") + container_list = Container.objects.order_by('-created_ts')[:5] + container_type_list = ContainerType.objects.order_by('-created_ts')[:5] + ctx = {'container_list': container_list, 'container_type_list': container_type_list} + return render(request, 'container/index.html', ctx) + +def container_type_details(request, container_type_id): + try: + ctype = ContainerType.objects.get(pk=container_type_id) + except ContainerType.DoesNotExist: + raise Http404("Container Type does not exist") + return render(request, 'container/container_type_details.html', {'container_type': ctype}) + +def container_details(request, container_id): + try: + container = Container.objects.get(pk=container_id) + except Container.DoesNotExist: + raise Http404("Container does not exist") + return render(request, 'container/container_details.html', {'container': container}) + diff --git a/homelog/settings.py b/homelog/settings.py index 2e97047..10309b1 100644 --- a/homelog/settings.py +++ b/homelog/settings.py @@ -31,6 +31,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'container.apps.ContainerConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes',