homelog/container/views.py

29 lines
1.1 KiB
Python

from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from django.http import Http404
from .models import Container, ContainerType
def index(request):
container_list = Container.objects.order_by('-created_ts')[:5]
container_type_list = ContainerType.objects.order_by('-created_ts')[:5]
ctx = {'container_list': container_list, 'container_type_list': container_type_list}
return render(request, 'container/index.html', ctx)
def container_type_details(request, container_type_id):
try:
ctype = ContainerType.objects.get(pk=container_type_id)
except ContainerType.DoesNotExist:
raise Http404("Container Type does not exist")
return render(request, 'container/container_type_details.html', {'container_type': ctype})
def container_details(request, container_id):
try:
container = Container.objects.get(pk=container_id)
except Container.DoesNotExist:
raise Http404("Container does not exist")
return render(request, 'container/container_details.html', {'container': container})