feature/filter-by-category #21

Merged
s470631 merged 2 commits from feature/filter-by-category into master 2022-01-09 22:44:26 +01:00
3 changed files with 7 additions and 2 deletions

View File

@ -10,4 +10,4 @@ urlpatterns = [
path('<category_name>', category), path('<category_name>', category),
] ]
urlpatterns = router.urls urlpatterns += router.urls

View File

@ -6,6 +6,7 @@ from categories.serializers import CategorySerializer
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.template import loader from django.template import loader
from trials.models import Test
class CategoryModelViewSet(viewsets.ModelViewSet): class CategoryModelViewSet(viewsets.ModelViewSet):
queryset = Category.objects.all() queryset = Category.objects.all()
@ -15,5 +16,5 @@ class CategoryModelViewSet(viewsets.ModelViewSet):
def category(request, category_name): def category(request, category_name):
context = {} context = {}
context['name'] = category_name context['name'] = category_name
context['tests'] = Test.objects.all(category=category_name) context['tests'] = Test.objects.filter(category=category_name)
return render(request, 'category.html', context) return render(request, 'category.html', context)

View File

@ -5,6 +5,7 @@ from rest_framework.response import Response
from trials.models import Test from trials.models import Test
from trials.serializers import TestSerializer from trials.serializers import TestSerializer
from django.conf import settings
class TestModelViewSet(viewsets.ModelViewSet): class TestModelViewSet(viewsets.ModelViewSet):
@ -14,6 +15,9 @@ class TestModelViewSet(viewsets.ModelViewSet):
class TestTemplateView(TemplateView): class TestTemplateView(TemplateView):
permission_classes = []
template_name = settings.BASE_DIR + f"/templates/generic_test.html"
def get_queryset(self): def get_queryset(self):
return Test.objects.all() return Test.objects.all()