List feature

+ implemented list feature
+ implemented category feature
This commit is contained in:
Clemens-Dautermann 2018-12-23 14:27:16 +01:00
parent 5877b83424
commit 32d60f51ac
23 changed files with 210 additions and 60 deletions

View file

@ -105,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/ # https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'de'
TIME_ZONE = 'Europe/Berlin' TIME_ZONE = 'Europe/Berlin'

View file

@ -20,6 +20,7 @@ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')), path('accounts/', include('django.contrib.auth.urls')),
path('', include('user_manager.urls')), path('', include('user_manager.urls')),
path('add/', include('object_adder.urls')) path('add/', include('object_adder.urls')),
path('list/', include('object_lister.urls'))
] ]

View file

@ -1,10 +1,15 @@
from django.contrib import admin from django.contrib import admin
from .models import Object from .models import Object, Category
class ObjectAdmin(admin.ModelAdmin): class ObjectAdmin(admin.ModelAdmin):
list_display = ('title', 'ammout', 'uuid', 'img') list_display = ('title', 'ammout', 'uuid', 'img')
class CategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'id')
# Register your models here. # Register your models here.
admin.site.register(Object, ObjectAdmin) admin.site.register(Object, ObjectAdmin)
admin.site.register(Category, CategoryAdmin)

View file

@ -1,12 +1,21 @@
from django.forms import ModelForm, TextInput from django.forms import ModelForm, TextInput
from .models import Object from .models import Object, Category
class ObjectForm(ModelForm): class ObjectForm(ModelForm):
class Meta: class Meta:
model = Object model = Object
fields = ('ammout', 'title', 'img', 'description') fields = ('ammout', 'title', 'img', 'description', 'category')
widgets = { widgets = {
'title': TextInput(), 'title': TextInput(),
} }
class CategoryForm(ModelForm):
class Meta:
model = Category
fields = ['name']
widgets = {
'name': TextInput()
}

View file

@ -1,4 +1,4 @@
# Generated by Django 2.1.4 on 2018-12-18 17:57 # Generated by Django 2.1.4 on 2018-12-22 19:20
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
@ -18,11 +18,14 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='Object', name='Object',
fields=[ fields=[
('ammout', models.PositiveIntegerField(default=1)),
('title', models.TextField(default=None, max_length=100)),
('img', models.ImageField(blank=True, default=None, upload_to='')),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('inventarized_date', models.DateTimeField()), ('inventarized_date', models.DateTimeField(null=True)),
('description', models.TextField(max_length=500)), ('description', models.TextField(blank=True, max_length=500)),
('removed_date', models.DateTimeField()), ('removed_date', models.DateTimeField(blank=True, default=None, null=True)),
('user_added', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ('user_added', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
], ],
), ),
] ]

View file

@ -1,18 +0,0 @@
# Generated by Django 2.1.4 on 2018-12-18 18:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('object_adder', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='object',
name='img',
field=models.ImageField(default=None, upload_to=''),
),
]

View file

@ -1,18 +0,0 @@
# Generated by Django 2.1.4 on 2018-12-18 18:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('object_adder', '0002_object_img'),
]
operations = [
migrations.AddField(
model_name='object',
name='title',
field=models.TextField(default=None, max_length=100),
),
]

View file

@ -14,3 +14,19 @@ class Object(models.Model):
description = models.TextField(max_length=500, blank=True) description = models.TextField(max_length=500, blank=True)
removed_date = models.DateTimeField(blank=True, default=None, null=True) removed_date = models.DateTimeField(blank=True, default=None, null=True)
user_added = models.ForeignKey(User, on_delete=models.CASCADE, blank=False, null=True) user_added = models.ForeignKey(User, on_delete=models.CASCADE, blank=False, null=True)
category = models.ForeignKey('Category', on_delete=models.CASCADE, blank=True, default=None, null=True)
objects = models.Manager()
def __str__(self):
return str(self.uuid)
class Category(models.Model):
name = models.TextField(blank=False, max_length=150)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
categories = models.Manager()
def __str__(self):
return self.name

View file

@ -3,4 +3,5 @@ from . import views
urlpatterns = [ urlpatterns = [
path('', views.add, name='add'), path('', views.add, name='add'),
path('kategorie', views.category, name='category')
] ]

View file

@ -1,6 +1,6 @@
from django.shortcuts import render from django.shortcuts import render
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from .forms import ObjectForm from .forms import ObjectForm, CategoryForm
from django.utils import timezone from django.utils import timezone
@ -31,3 +31,21 @@ def add(request):
else: else:
context = {'title': 'Objekt inventarisieren', 'form': ObjectForm} context = {'title': 'Objekt inventarisieren', 'form': ObjectForm}
return render(request, 'object_adder/index.html', context) return render(request, 'object_adder/index.html', context)
@login_required
def category(request):
if request.method == 'POST':
form = CategoryForm(request.POST)
if form.is_valid():
cat = form.save()
cat.save()
context = {'title': 'Neue Kategorie hinzufügen',
'cat_name': form.cleaned_data.get('name'),
'form': CategoryForm}
return render(request, 'object_adder/category.html', context)
else:
context = {'form': CategoryForm, 'title': 'Neue Kategorie hinzufügen'}
return render(request, 'object_adder/category.html', context)

View file

View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class ObjectListerConfig(AppConfig):
name = 'object_lister'

View file

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View file

@ -0,0 +1,6 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.objlist, name='objlist'),
]

View file

@ -0,0 +1,13 @@
from django.shortcuts import render
from object_adder.models import Object
from django.contrib.auth.decorators import login_required
# Create your views here.
@login_required
def objlist(request):
objects = Object.objects.all()
context = {'title': 'Inventar', 'objects': objects}
return render(request, 'object_lister/index.html', context)

View file

@ -57,14 +57,12 @@
} }
.title-wrapper * { .title-wrapper * {
vertical-align: middle; vertical-align: middle;
} }
#id_img { #id_img {
display: inline-block; display: inline-block;
margin-left: 1.2em;
} }
@ -80,3 +78,41 @@
width: 18em; width: 18em;
height: 5em; height: 5em;
} }
.catform * {
margin-top: 0.7em;
}
.btnwrapper {
display: flex;
align-items: center;
}
.newcatlink {
margin-left: 2em;
}
.objecttable {
border-collapse: collapse;
width: 100%;
margin-top: 2em;
margin-bottom: 2em;
}
.objecttable-data, .objecttable-head {
border: 1px solid #dddddd;
text-align: center;
padding: 0.4em;
}
.objecttable-row:nth-child(even) {
background-color: #dddddd;
}
.objecttable-row:hover {
-webkit-box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.1);
box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.1);
border-radius: 10px;
transition: 0.1s;
}

View file

@ -37,6 +37,7 @@
<li><a href="{% url 'index' %}">Home</a></li> <li><a href="{% url 'index' %}">Home</a></li>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li><a href="{% url 'add' %}">Objekt inventarisieren</a></li> <li><a href="{% url 'add' %}">Objekt inventarisieren</a></li>
<li><a href="{% url 'objlist' %}">Inventar</a></li>
{% endif %} {% endif %}
</ul> </ul>
{% if user.is_authenticated %} {% if user.is_authenticated %}

View file

@ -0,0 +1,27 @@
{% extends 'bases/navbar.html' %}
<html>
{% block content %}
<body>
<div class="container shadow">
{% if not cat_name is None %}
<div class="alert alert-info alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
Die Kategorie <strong>{{ cat_name }}</strong> wurde erstellt!
</div>
{% endif %}
<form method="POST" class="post-form invform">
{% csrf_token %}
<div class="name-wrapper">
{{ form.name.errors }}
<label for="{{ form.name.id_for_lable }}">Kategorie:</label>
{{ form.name }}
</div>
<button type="submit" class="save btn btn-primary">Kategorie hinzufügen</button>
</form>
</div>
</body>
{% endblock %}
</html>

View file

@ -3,7 +3,7 @@
{% block content %} {% block content %}
<body> <body>
<div class="container"> <div class="container shadow">
{% if not obj_name is None %} {% if not obj_name is None %}
<div class="alert alert-info alert-dismissible"> <div class="alert alert-info alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
@ -22,6 +22,11 @@
<label for="{{ form.title.id_for_lable }}">Objekt:</label> <label for="{{ form.title.id_for_lable }}">Objekt:</label>
{{ form.title }} {{ form.title }}
</div> </div>
<div class="category-wrapper">
{{ form.category.errors }}
<label for="{{ form.category.id_for_lable }}">Kategorie:</label>
{{ form.category }}
</div>
<div class="img-wrapper"> <div class="img-wrapper">
{{ form.img.errors }} {{ form.img.errors }}
<label for="{{ form.img.id_for_lable }}">Bild:</label> <label for="{{ form.img.id_for_lable }}">Bild:</label>
@ -32,8 +37,10 @@
<label for="{{ form.description.id_for_lable }}">Beschreibung:</label> <label for="{{ form.description.id_for_lable }}">Beschreibung:</label>
{{ form.description }} {{ form.description }}
</div> </div>
<div class="btnwrapper">
<button type="submit" class="save btn btn-primary">inventarisieren</button> <button type="submit" class="save btn btn-primary">inventarisieren</button>
<a href="./kategorie" class="newcatlink">Neue Kategorie hinzufügen</a>
</div>
</form> </form>
</div> </div>
</body> </body>

View file

@ -0,0 +1,29 @@
{% extends 'bases/navbar.html' %}
<html>
{% block content %}
<body>
<div class="container shadow">
<table class="objecttable">
<tr class="objecttable-row">
<th class="objecttable-head">Name</th>
<th class="objecttable-head">Anzahl</th>
<th class="objecttable-head">Kategorie</th>
<th class="objecttable-head">Inventarisierungsdatum</th>
<th class="objecttable-head">Hinzugefügt von</th>
</tr>
{% for object in objects %}
<tr class="objecttable-row">
<td class="objecttable-data">{{ object.title }}</td>
<td class="objecttable-data">{{ object.ammout }}</td>
<td class="objecttable-data">{{ object.category }}</td>
<td class="objecttable-data">{{ object.inventarized_date }}</td>
<td class="objecttable-data">{{ object.user_added }}</td>
</tr>
{% endfor %}
</table>
</div>
</body>
{% endblock %}
</html>