Browse Source

Praktikum #6 fertig

devel
Lennart Heimbs 5 years ago
parent
commit
8cddca2955
5 changed files with 28 additions and 3 deletions
  1. 4
    0
      .gitignore
  2. 1
    0
      news/news/settings.py
  3. 5
    0
      news/posts/models.py
  4. 9
    2
      news/posts/views.py
  5. 9
    1
      news/templates/posts/index.html

+ 4
- 0
.gitignore View File



# mypy # mypy
.mypy_cache/ .mypy_cache/


# vscode
.vscode/

+ 1
- 0
news/news/settings.py View File

# Application definition # Application definition


INSTALLED_APPS = [ INSTALLED_APPS = [
'posts.apps.PostsConfig',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',

+ 5
- 0
news/posts/models.py View File

from django.db import models from django.db import models


# Create your models here. # 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
news/posts/views.py View File

from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Notice
from django.utils import timezone


# Create your views here. # Create your views here.
def index(request): 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)

+ 9
- 1
news/templates/posts/index.html View File

{% block content %} {% block content %}
<div class="jumbotron"> <div class="jumbotron">
<h1 class="display-4">Index of News App</h1> <h1 class="display-4">Index of News App</h1>
<p class="lead">Some placeholder Text</p>

<div class=container>
{% for notice in notices %}
<h3>{{ notice.notice_title }}</h3>
<p>{{ notice.notice_text }}</p>
{% endfor %}
</div>

<!--p class="lead">Some placeholder Text</p-->
</div> </div>
{% endblock %} {% endblock %}

Loading…
Cancel
Save