Aufgabe6
This commit is contained in:
Binary file not shown.
@@ -37,7 +37,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'posts'
|
||||
'posts.apps.PostsConfig',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
+2
-2
@@ -15,9 +15,9 @@ Including another URLconf
|
||||
"""
|
||||
|
||||
from django.contrib import admin
|
||||
from django.urls import path,
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
urlpatterns = [
|
||||
path('posts/', include('posts.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 2.2.7 on 2019-11-19 13:22
|
||||
|
||||
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()),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -1,3 +1,7 @@
|
||||
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()
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
#create your views here.
|
||||
from .models import Notice
|
||||
from django.utils import timezone
|
||||
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)
|
||||
@@ -0,0 +1,18 @@
|
||||
{% extends 'posts/base.html'%}
|
||||
|
||||
{% block title %}
|
||||
News
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container">
|
||||
|
||||
{% for notice in notices %}
|
||||
<h3>{{ notice.notice_title }}</h3>}}
|
||||
<P> {{ notice.notice_text }}<p>
|
||||
{% endfor %}
|
||||
|
||||
</div>}
|
||||
|
||||
{% endblock %}
|
||||
@@ -58,6 +58,6 @@
|
||||
<section id="content">
|
||||
{% block content %}{% endblock %}
|
||||
</section>
|
||||
<footer>© posts news1</footer>
|
||||
<footer>posts news1</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends 'posts/base.html'%}
|
||||
{% block content %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
<div class="jumbotron">
|
||||
|
||||
Reference in New Issue
Block a user