Browse Source

Not Working condition

master
Lukas Weber 2 years ago
parent
commit
72c6a3762d
8 changed files with 80 additions and 11 deletions
  1. 13
    0
      posts/forms.py
  2. 6
    0
      posts/models.py
  3. 3
    1
      posts/urls.py
  4. 29
    3
      posts/views.py
  5. 1
    5
      templates/base.html
  6. 10
    0
      templates/posts/edit.html
  7. 16
    1
      templates/posts/index.html
  8. 2
    1
      webengdjango/settings.py

+ 13
- 0
posts/forms.py View File

@@ -0,0 +1,13 @@
from django import forms
import datetime

class NoticeForm(forms.Form):
date_formats = ['%d.%m.%Y', '%d.%m.%y']
title = forms.CharField(label='Titel', max_length=80)
text = forms.CharField(label='Text', max_length=400)
start = forms.DateField(label='Von',
input_formats=date_formats,
initial=datetime.date.today)
end = forms.DateField(label='Bis',
input_formats=date_formats,
initial=datetime.date.today)

+ 6
- 0
posts/models.py View File

@@ -1,3 +1,9 @@
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()

+ 3
- 1
posts/urls.py View File

@@ -2,5 +2,7 @@ from django.urls import path
from . import views

urlpatterns = [
path('', views.index, name = 'index')
path('edit', views.new, name='new'),
path('', views.index, name = 'index'),
path('delete/int:id/', views.delete, name ='delete')
]

+ 29
- 3
posts/views.py View File

@@ -1,5 +1,31 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import render, redirect, HttpResponse
from django.utils import timezone

from .forms import NoticeForm
from .models import Notice


def index(request):
return HttpResponse("Index der Seite Posts Applikation")
notices = Notice.objects.all()
notices.filter(pub_start__lte=timezone.now())
notices.filter(pub_start__gte=timezone.now())
context = { "notices": notices }
return render(request, 'posts/index.html', context)

def new(request):
if request.method == "POST":
form = NoticeForm(request.POST)
if form.is_valid():
newNotice = Notice(notice_title=form.cleaned_data['title'],
notice_text=form.cleaned_data['text'],
pub_start = form.cleaned_data['start'],
pub_end = form.cleaned_data['end'])
newNotice.save()
return redirect('index')
context = {'form': NoticeForm()}
return render(request, 'posts/edit.html', context)


def delete(request):
notices = Notice.objects.all()
notices.filter()

+ 1
- 5
templates/base.html View File

@@ -3,13 +3,9 @@
<head>
<title>My first page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron">
<div>
{% block body %} Platzhalter {% endblock body %}
</div>
</body>

+ 10
- 0
templates/posts/edit.html View File

@@ -0,0 +1,10 @@
{% extends "base.html" %}

{% block body %}
<h1>Neue Nachricht </h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-default">Speichern</button>
</form>
{% endblock %}

+ 16
- 1
templates/posts/index.html View File

@@ -1,2 +1,17 @@
{% extends "base.html" %}
{% block body %} <h1> sytle="text-align:center" {{ name }} </h1> {% endblock body %}

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

{% block body %}

<div>
{% for notice in notices %}
<h3> {{ notice.notice_title }}</h3>
<p> {{ notice.notice_text }}</p>
<p><a class="btn btn-info" role="button"> href={% url 'delete' id=n %} Löschen </a></p>
{% endfor %}
</div>
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
{% endblock %}

+ 2
- 1
webengdjango/settings.py View File

@@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
# Application definition

INSTALLED_APPS = [
'posts.apps.PostsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
@@ -104,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'de-de'

TIME_ZONE = 'UTC'


Loading…
Cancel
Save