g214/results/views.py

41 lines
1.3 KiB
Python

# coding:utf-8
from django.shortcuts import render
from .models import Paper, WinResult, ResultStandard, Patent
# Create your views here.
def results(request):
contents2 = []
contents = []
category = request.GET.get('category')
if category == '1':
try:
contents = Paper.objects.all().order_by('number')
except Paper.DoesNotExist:
contents = []
if category == '2':
try:
contents = WinResult.objects.all().order_by('number')
except WinResult.DoesNotExist:
contents = []
if category == '3':
try:
contents = ResultStandard.objects.all().order_by('number')
except ResultStandard.DoesNotExist:
contents = []
if category == '4':
try:
contents = Patent.objects.filter(category='4').order_by('number')
except Patent.DoesNotExist:
contents = []
try:
contents2 = Patent.objects.filter(category='5').order_by('number')
except Patent.DoesNotExist:
contents2 = []
return render(request, 'results/index.html', {"category": category,
"contents": contents,
"contents2": contents2})