Files
tealcode-django-python/TealCode/main/views.py
DerTyp187 3606b86c02 a-current
a
2021-11-10 12:56:03 +01:00

38 lines
1.1 KiB
Python

from django.shortcuts import render, redirect
from .models import Category, Topic
def index(req):
return render(req, "main/index.html")
def topic(req, category, topic):
if topic and category:
category_obj = Category.objects.filter(title = category).first()
if category_obj:
topic_obj = Topic.objects.filter(title=topic, category = category_obj).first()
if topic_obj:
context = {
'title': topic_obj.title,
'code': topic_obj.code_text,
'category_title': category_obj.title,
}
return render(req, "main/topic.html", context)
return redirect("main-index")
def category(req, category):
if category:
category_obj = Category.objects.filter(title = category).first()
if category_obj:
topics_obj = Topic.objects.filter(category=category_obj)
return render(req, "main/category.html", {'category_obj': category_obj, 'topics': topics_obj})
return redirect("main-index")