djangoprojekt
This commit is contained in:
@@ -5,3 +5,9 @@ class Notice(models.Model):
|
||||
pub_start = models.DateTimeField()
|
||||
pub_end = models.DateTimeField()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
from django.shortcuts import render
|
||||
from.models import Notice
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
# Create your views here.
|
||||
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/notice.html', context)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user