Browse Source

djangoprojekt

master
parent
commit
f434511bd0
4 changed files with 31 additions and 11 deletions
  1. BIN
      news1/db.sqlite3
  2. 1
    1
      news1/news1/settings.py
  3. 4
    1
      news1/posts/urls.py
  4. 26
    9
      news1/posts/views.py

BIN
news1/db.sqlite3 View File


+ 1
- 1
news1/news1/settings.py View File

# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/ # https://docs.djangoproject.com/en/2.2/topics/i18n/


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


TIME_ZONE = 'UTC' TIME_ZONE = 'UTC'



+ 4
- 1
news1/posts/urls.py View File

from django.urls import path from django.urls import path

from.import views from.import views


urlpatterns =[ urlpatterns =[
path('', views.index, name='index'), path('', views.index, name='index'),
path('new', views.new, name='new'),
path('delete/<int:deleteId>', views.delete, name='delete'),
] ]

+ 26
- 9
news1/posts/views.py View File

from django.shortcuts import render
from django.shortcuts import render, redirect

from posts.forms import NoticeForm
from.models import Notice from.models import Notice
from django.utils import timezone from django.utils import timezone
from django.http import HttpResponse


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







return render(request, 'posts/notice.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, deleteId=None):
if deleteId !=None:
delNotice= Notice.objects.get(id=deleteId)
if delNotice!= None:
delNotice.delete()
return redirect('index')

Loading…
Cancel
Save