Browse Source

praktikum Sechs bearbeitung

master
parent
commit
73437a9a7a
6 changed files with 140 additions and 3 deletions
  1. 90
    0
      .gitignore
  2. 1
    0
      news/settings.py
  3. 24
    0
      posts/migrations/0001_initial.py
  4. 5
    0
      posts/models.py
  5. 8
    1
      posts/views.py
  6. 12
    2
      templates/posts/index.html

+ 90
- 0
.gitignore View File

@@ -0,0 +1,90 @@
### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Sphinx documentation
docs/_build/

# PyBuilder
target/


### Django ###
*.log
*.pot
*.pyc
**__pycache__/
local_settings.py

.env
**/db.sqlite3

# PyCharm
**/.idea/

+ 1
- 0
news/settings.py View File

@@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'posts.apps.PostsConfig',
]

MIDDLEWARE = [

+ 24
- 0
posts/migrations/0001_initial.py View File

@@ -0,0 +1,24 @@
# Generated by Django 2.2.7 on 2019-11-19 13:28

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Notice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('notice_title', models.CharField(max_length=80)),
('notice_text', models.CharField(max_length=400)),
('pub_start', models.DateTimeField()),
('pub_end', models.DateTimeField()),
],
),
]

+ 5
- 0
posts/models.py View File

@@ -1,3 +1,8 @@
from django.db import models

# Create your models here.
class Notice(models.Model):
notice_title = models.CharField(max_length=80)
notice_text = models.CharField(max_length=400)
pub_start = models.DateTimeField()
pub_end = models.DateTimeField()

+ 8
- 1
posts/views.py View File

@@ -1,6 +1,13 @@
from django.shortcuts import render
from .models import Notice
from django.utils import timezone



def index (request):
return render(request, 'posts/index.html')
notices = Notice.objects.all()
notices = notices.filter(pub_start__lte=timezone.now())
notices = notices.filter(pub_end__gte=timezone.now())
context = { "notices" : notices }
return render(request, 'posts/index.html', context)


+ 12
- 2
templates/posts/index.html View File

@@ -1,11 +1,22 @@
{% extends 'base.html' %}

{% block title %}
Index
News
{% endblock %}

{% block content %}

<div class="container">

{% for notice in notices %}
<h3>{{ notice.notice_title }}</h3>
<p>{{ notice.notice_text }}</p>
{% endfor %}

</div>

{% endblock %}


<!DOCTYPE html>
<html>
@@ -37,4 +48,3 @@
</body>
</html>
<h1> Index der Polls-Applikation</h1>
{% endblock %}

Loading…
Cancel
Save