@@ -15,9 +15,10 @@ Including another URLconf | |||
""" | |||
from django.contrib import admin | |||
from django.urls import path, include | |||
from. import views | |||
urlpatterns = [ | |||
path('', include('posts.urls')), | |||
path('', views.index, name="index"), | |||
path('posts/', include('posts.urls')), | |||
path('admin/', admin.site.urls), | |||
] |
@@ -0,0 +1,15 @@ | |||
from django.shortcuts import render | |||
from django.http import HttpResponse | |||
logger = None | |||
def init_loger(): | |||
global logger | |||
if not logger: | |||
logger = logging.getLogger(__name__) | |||
logger.setLevel(logging.DEBUG) | |||
logger.addHandler(logging.StreamHandler) | |||
# Create your views here. | |||
def index(request): | |||
return render(request, 'news/index.html') |
@@ -0,0 +1,24 @@ | |||
# Generated by Django 2.2.6 on 2019-11-19 12:29 | |||
from django.db import migrations, models | |||
class Migration(migrations.Migration): | |||
initial = True | |||
dependencies = [ | |||
] | |||
operations = [ | |||
migrations.CreateModel( | |||
name='Notice', | |||
fields=[ | |||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | |||
('notice_title', models.CharField(max_length=80)), | |||
('notice_text', models.CharField(max_length=400)), | |||
('pub_start', models.DateTimeField()), | |||
('pub_end', models.DateTimeField()), | |||
], | |||
), | |||
] |
@@ -2,5 +2,5 @@ from django.urls import path | |||
from . import views | |||
urlpatterns = [ | |||
path('', views.index, name='index') | |||
path('', views.index, name='posts') | |||
] |
@@ -2,12 +2,22 @@ from django.shortcuts import render | |||
from django.http import HttpResponse | |||
from .models import Notice | |||
from django.utils import timezone | |||
import logging | |||
logger = None | |||
def init_loger(): | |||
global logger | |||
if logger == None: | |||
logger = logging.getLogger('django.db.backends') | |||
logger.setLevel(logging.DEBUG) | |||
logger.addHandler(logging.StreamHandler()) | |||
# Create your views here. | |||
def index(request): | |||
init_loger() | |||
notices = Notice.objects.all() | |||
notices = Notice.objects.filter(pub_start__lte=timezone.now()) | |||
notices = Notice.objects.filter(pub_end__gte=timezone.now()) | |||
notices = Notice.objects.filter(pub_start__lte=timezone.now(), pub_end__gte=timezone.now()) | |||
context = { | |||
"notices": notices, | |||
} |
@@ -6,7 +6,7 @@ | |||
<a class="nav-link" href="{% url 'index' %}">Home</a> | |||
</li> | |||
<li class="nav-item"> | |||
<a class="nav-link" href="{% url 'index' %}">Posts</a> | |||
<a class="nav-link" href="{% url 'posts' %}">Posts</a> | |||
</li> | |||
<li class="nav-item"> | |||
<a class="nav-link" href="https://www.th-nuernberg.de/fakultaeten/efi/">EFI</a> |
@@ -0,0 +1,13 @@ | |||
{% extends 'base.html' %} | |||
{% block title %} | |||
Index | |||
{% endblock %} | |||
{% block content %} | |||
<div class="jumbotron"> | |||
<h1 class="display-4">Index of News App</h1> | |||
<p class="lead">Some placeholder Text</p> | |||
</div> | |||
{% endblock %} |