Merge pull request 'feature/filter-by-category' (#21) from feature/filter-by-category into master

Reviewed-on: #21
This commit is contained in:
s470631 2022-01-09 22:44:26 +01:00
commit 723e36c36a
3 changed files with 7 additions and 2 deletions

View File

@ -10,4 +10,4 @@ urlpatterns = [
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.shortcuts import render, redirect
from django.template import loader
from trials.models import Test
class CategoryModelViewSet(viewsets.ModelViewSet):
queryset = Category.objects.all()
@ -15,5 +16,5 @@ class CategoryModelViewSet(viewsets.ModelViewSet):
def category(request, category_name):
context = {}
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)

View File

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