First models and views
This commit is contained in:
parent
fea6cdcf96
commit
6171384e14
|
@ -1,2 +1,34 @@
|
||||||
db.sqlite3
|
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
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
from django.contrib import admin
|
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)
|
||||||
|
|
||||||
|
|
|
@ -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)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -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',
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,3 +1,33 @@
|
||||||
from django.db import models
|
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.
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<h1>Container: {{ container.named_id }}</h1>
|
||||||
|
<div>{{ container.description }}</div>
|
||||||
|
<div>Color: {{ container.color }}</div>
|
||||||
|
<div>Container Type: <a href='/container/type/{{ container.container_type.id }}'>{{ container.container_type.named_id }}</a></div>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<h1>Container: {{ container_type.named_id }}</h1>
|
||||||
|
<div>{{ container_type.description }}</div>
|
||||||
|
<table>
|
||||||
|
<tr><td>Width:</td><td>{{ container_type.width }} mm</td><td>Inner Width:</td><td>{{ container_type.inner_width }} mm</td></tr>
|
||||||
|
<tr><td>Length:</td><td>{{ container_type.length }} mm</td><td>Inner Length:</td><td>{{ container_type.inner_length }} mm</td></tr>
|
||||||
|
<tr><td>Height:</td><td>{{ container_type.height }} mm</td><td>Inner Height:</td><td>{{ container_type.inner_height }} mm</td></tr>
|
||||||
|
<tr><td>Has Cover:</td><td>{% if container_type.has_cover %} yes {% else %} no {% endif %}</td><td>Can hold Containers:</td><td>{% if container_type.contains_container %} yes {% else %} no {% endif %}</td></tr>
|
||||||
|
</table>
|
|
@ -0,0 +1,24 @@
|
||||||
|
<div>
|
||||||
|
<div>New Container:</div>
|
||||||
|
{% if container_list %}
|
||||||
|
<ul>
|
||||||
|
{% for container in container_list %}
|
||||||
|
<li><a href="/container/{{ container.id }}/">{{ container.named_id }} {{ container.description }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>No container are available.</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div>New Container Types:</div>
|
||||||
|
{% if container_type_list %}
|
||||||
|
<ul>
|
||||||
|
{% for ctype in container_type_list %}
|
||||||
|
<li><a href="/container/type/{{ ctype.id }}/">{{ ctype.named_id }} {{ ctype.description }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>No container types are available.</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
|
@ -4,5 +4,8 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
|
path('<int:container_id>/', views.container_details, name='container_details'),
|
||||||
|
path('type/<int:container_type_id>/', views.container_type_details, name='container_type_details'),
|
||||||
|
# path('type/<string:container_type_named_id>/', views.container_type_details, name='container_type_details'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,28 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.template import loader
|
||||||
|
from django.http import Http404
|
||||||
|
|
||||||
|
from .models import Container, ContainerType
|
||||||
|
|
||||||
def index(request):
|
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})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
'container.apps.ContainerConfig',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
|
|
Loading…
Reference in New Issue