dr.botzo/facts/views.py
Brian S. Stephan fb04732ec3 facts: recreate the choices experience in facts
recreates the choices view in facts, allowing for display of any fact
category in the system, and providing a random item from it

bss/dr.botzo#15
2017-02-11 09:34:15 -06:00

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})