homelog/container/views.py

29 lines
1.1 KiB
Python
Raw Normal View History

2022-03-09 10:33:05 +00:00
from django.shortcuts import render
from django.http import HttpResponse
2022-03-09 17:13:09 +00:00
from django.template import loader
from django.http import Http404
2022-03-09 10:33:05 +00:00
2022-03-09 17:13:09 +00:00
from .models import Container, ContainerType
2022-03-09 10:33:05 +00:00
def index(request):
2022-03-09 17:13:09 +00:00
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})
2022-03-09 10:33:05 +00:00