Praktikum #6 fertig

This commit is contained in:
Lennart Heimbs
2019-11-19 12:48:20 +01:00
parent 059f9e6d11
commit 8cddca2955
5 changed files with 28 additions and 3 deletions
+5
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()
+9 -2
View File
@@ -1,7 +1,14 @@
from django.shortcuts import render
from django.http import HttpResponse
from .models import Notice
from django.utils import timezone
# Create your views here.
def index(request):
return render(request, 'posts/index.html')
#HttpResponse("Posts Index")
notices = Notice.objects.all()
notices = Notice.objects.filter(pub_start__lte=timezone.now())
notices = Notice.objects.filter(pub_end__gte=timezone.now())
context = {
"notices": notices,
}
return render(request, 'posts/index.html', context)