diff --git a/.gitignore b/.gitignore index 894a44c..40c2af6 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,7 @@ venv.bak/ # mypy .mypy_cache/ + + +# vscode +.vscode/ diff --git a/news/news/settings.py b/news/news/settings.py index 951178c..49d37cf 100644 --- a/news/news/settings.py +++ b/news/news/settings.py @@ -31,6 +31,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'posts.apps.PostsConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/news/posts/models.py b/news/posts/models.py index 71a8362..5058462 100644 --- a/news/posts/models.py +++ b/news/posts/models.py @@ -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() \ No newline at end of file diff --git a/news/posts/views.py b/news/posts/views.py index 3a8276c..caca9d3 100644 --- a/news/posts/views.py +++ b/news/posts/views.py @@ -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") \ No newline at end of file + 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) diff --git a/news/templates/posts/index.html b/news/templates/posts/index.html index b75142c..8826ea3 100644 --- a/news/templates/posts/index.html +++ b/news/templates/posts/index.html @@ -7,6 +7,14 @@ Index {% block content %}

Index of News App

-

Some placeholder Text

+ +
+ {% for notice in notices %} +

{{ notice.notice_title }}

+

{{ notice.notice_text }}

+ {% endfor %} +
+ +
{% endblock %}