fill datenbank app

This commit is contained in:
erichhasl
2017-11-18 15:49:30 +01:00
parent 993044ed58
commit b1bf306522
9 changed files with 106 additions and 92 deletions
+7
View File
@@ -1,3 +1,10 @@
from django.contrib import admin
from .models import Entry
# Register your models here.
class EntryAdmin(admin.ModelAdmin):
pass
admin.site.register(Entry, EntryAdmin)
+6
View File
@@ -1,3 +1,9 @@
from django.db import models
# Create your models here.
class Entry(models.Model):
title = models.CharField(max_length=100)
pub_date = models.DateTimeField('Veröffentlichungsdatum')
image = models.ImageField('Vorschaubild', upload_to='thumbnails')
element = models.FileField('Datei', upload_to='datastorage')
@@ -0,0 +1,45 @@
#datenbank_html {
margin-left: 2%;
width: 96%;
}
.tabledatabase {
width: 100%;
}
.trdatabase {
padding-top: 50px;
padding-bottom: 50px;
}
.tddatabase {
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-top: 10px;
}
.thumbnail {
display: inline-block;
border: 1px solid black;
width: 20%;
}
img {
max-width: 100%;
height: auto;
}
div.polaroid {
border: 2px solid #e7e7e7;
width: 80%;
background-color: white;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
margin-bottom: 25px;
}
div.container {
text-align: center;
padding: 10px 20px;
font-family: Helvetica, serif;
font-size: 12px;
}
#description {
text-align: center;
}
@@ -1,5 +1,35 @@
{% extends "public/default.html" %}
{% load static %}
{% block content %}
<p>Datenbank</p>
<link rel="stylesheet" type="text/css" href="{% static "datenbank/css/index.css"%}">
<div id="datenbank_html">
<table class="tabledatabase">
<tr class="trdatabase">
<td class="tddatabase", colspan=4>
<p id="description">
Dies ist eine Datenbank mit allen Dokumenten, die die
Goethopische Agentur für politische Bildung herausgebracht hat.
Jedes der Elemente ist auf das dazugehörige PDF-Dokument verlinkt.
</p>
</td>
</tr>
{% for row in rows %}
<tr class="trdatabase">
{% for entry in row %}
<td class="tddatabase", align="{% cycle "left" "center" "right" %}">
<div class="polaroid">
<a class="thumbnail" href="{{ entry.element.url }}">
<img src="{{ entry.image.url }}" alt="Verfassung">
</a>
<div class="container">
<p>{{ entry.title }}</p>
</div>
</div>
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
+10 -1
View File
@@ -1,6 +1,15 @@
from django.shortcuts import render
import math
from .models import Entry
# Create your views here.
def index(request):
return render(request, "datenbank/index.html")
rows = group(Entry.objects.all(), 3)
print("rows", rows)
return render(request, "datenbank/index.html", {'rows': rows})
def group(l, n):
return [l[k*n:k*n+n] for k in range(math.ceil(len(l) / n))]