dr.botzo/facts/views.py

27 lines
826 B
Python

"""Display fact categories."""
import logging
from django.shortcuts import get_object_or_404, render
from facts.models import FactCategory
log = logging.getLogger(__name__)
def index(request):
"""Display a simple list of the fact categories, for the moment."""
factcategories = FactCategory.objects.all()
return render(request, 'facts/index.html', {'factcategories': factcategories})
def factcategory_detail(request, factcategory_name):
"""Display info, and a random choice, for the fact category."""
factcategory = get_object_or_404(FactCategory, name=factcategory_name)
facts = []
if factcategory.show_all_entries:
facts = [x.fact for x in factcategory.fact_set.all()]
return render(request, 'facts/factcategory_detail.html', {'factcategory': factcategory, 'facts': facts})