Erster View und erstes Template angelegt, URL /speisekarte registriert. #1
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
mensa_app/__pycache__/urls.cpython-314.pyc
Normal file
BIN
mensa_app/__pycache__/urls.cpython-314.pyc
Normal file
Binary file not shown.
BIN
mensa_app/__pycache__/views.cpython-314.pyc
Normal file
BIN
mensa_app/__pycache__/views.cpython-314.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
55
mensa_app/templates/mensa_app/gericht_list.html
Normal file
55
mensa_app/templates/mensa_app/gericht_list.html
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Mensa-Speisekarte</title>
|
||||||
|
<!-- Bootstrap CSS für schnelles Styling -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body class="bg-light">
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div class="card shadow">
|
||||||
|
<div class='card-header bg-primary text-white text-center py-3'>
|
||||||
|
<h1><i class="bi bi-egg-fried"></i> Unsere Speisekarte</h1>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead class="table-dark">
|
||||||
|
<tr>
|
||||||
|
<th>Gericht</th>
|
||||||
|
<th>Kategorie</th>
|
||||||
|
<th>Status</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for gericht in alle_gerichte %}
|
||||||
|
<tr>
|
||||||
|
<td><strong>{{ gericht.name }}</strong></td>
|
||||||
|
<td><span class="badge bg-info text-dark">{{ gericht.kategorie.name }}</span></td>
|
||||||
|
<td>
|
||||||
|
{% if gericht.ist_dauerangebot %}
|
||||||
|
<span class="badge bg-success">Dauerangebot</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="badge bg-secondary">Tagesangebot</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% empty %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="3" class="text-center text-muted">Keine Gerichte im System gefunden.</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
8
mensa_app/urls.py
Normal file
8
mensa_app/urls.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from .views import GerichtListView
|
||||||
|
from .views import SpeiseplanView # Achte auf den neuen Klassennamen!
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('speisekarte/', GerichtListView.as_view(), name='gericht_list'),
|
||||||
|
path('speiseplan/', SpeiseplanView.as_view(), name='speiseplan'),
|
||||||
|
]
|
||||||
@@ -1,3 +1,50 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
from django.views.generic import ListView
|
||||||
|
from .models import Gericht
|
||||||
|
|
||||||
|
class GerichtListView(ListView):
|
||||||
|
model = Gericht
|
||||||
|
template_name = 'mensa_app/gericht_liste.html' # Der Pfad zum Template
|
||||||
|
context_object_name = 'alle_gerichte' # Der Name, den wir im Template nutzen
|
||||||
|
|
||||||
|
from django.views.generic import TemplateView
|
||||||
|
from django.utils import timezone
|
||||||
|
from datetime import datetime
|
||||||
|
from .models import Menue, Gericht, SpeiseplanTag
|
||||||
|
|
||||||
|
class SpeiseplanView(TemplateView):
|
||||||
|
template_name = 'mensa_app/speiseplan.html'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
# 1. Datum aus der URL holen (z.B. ?datum=2023-10-27)
|
||||||
|
# Wenn kein Datum angegeben ist, nehmen wir heute.
|
||||||
|
date_str = self.request.GET.get('datum')
|
||||||
|
if date_str:
|
||||||
|
try:
|
||||||
|
target_date = datetime.strptime(date_str, '%Y-%m-%d').date()
|
||||||
|
except ValueError:
|
||||||
|
target_date = timezone.glob.now().date()
|
||||||
|
else:
|
||||||
|
target_date = timezone.now().date()
|
||||||
|
|
||||||
|
# 2. Menüs für diesen spezifischen Tag laden
|
||||||
|
# Wir suchen alle Menüs, deren Tag das target_date hat
|
||||||
|
context['target_date'] = target_date
|
||||||
|
context['menues_day'] = Menue.objects.filter(tag__datum=target_date)
|
||||||
|
|
||||||
|
# 3. Dauerangebote laden (unabhängig vom Tag)
|
||||||
|
context['dauerangebote'] = Gericht.objects.filter(ist_dauerangebot=True)
|
||||||
|
|
||||||
|
# 4. Pager-Logik: Vorherigen und nächsten Tag finden
|
||||||
|
# Wir suchen in der Tabelle SpeiseplanTag nach dem Tag davor/danach
|
||||||
|
prev_tag = SpeiseplanTag.objects.filter(datum__lt=target_date).order_by('-datum').first()
|
||||||
|
next_tag = SpeiseplanTag.objects.filter(datum__gt=target_date).order_by('datum').first()
|
||||||
|
|
||||||
|
context['prev_date'] = prev_tag.datum.strftime('%Y-%m-%d') if prev_tag else None
|
||||||
|
context['next_date'] = next_tag.datum.strftime('%Y-%m-%d') if next_tag else None
|
||||||
|
|
||||||
|
return context
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -15,8 +15,9 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('', include('mensa_app.urls')), # Schaltet die App-URLs frei
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user