From bc6d973bf328217aec74e0e54ecca90405cdd159 Mon Sep 17 00:00:00 2001 From: Hubert Jankowski Date: Sun, 9 Jan 2022 22:29:40 +0100 Subject: [PATCH 1/2] filter by category --- categories/urls.py | 2 +- categories/views.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/categories/urls.py b/categories/urls.py index 5cd5b3e..8ff1759 100644 --- a/categories/urls.py +++ b/categories/urls.py @@ -10,4 +10,4 @@ urlpatterns = [ path('', category), ] -urlpatterns = router.urls +urlpatterns += router.urls diff --git a/categories/views.py b/categories/views.py index 17c5326..e975457 100644 --- a/categories/views.py +++ b/categories/views.py @@ -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) \ No newline at end of file From 378d758e4ae6b995cdbec7ffc71a119aed84335e Mon Sep 17 00:00:00 2001 From: Hubert Jankowski Date: Sun, 9 Jan 2022 22:43:49 +0100 Subject: [PATCH 2/2] Fixed test show --- trials/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/trials/views.py b/trials/views.py index fd086a5..4a47e5d 100644 --- a/trials/views.py +++ b/trials/views.py @@ -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()