Merge pull request 'feature/filter-by-category' (#21) from feature/filter-by-category into master
Reviewed-on: #21
This commit is contained in:
commit
723e36c36a
@ -10,4 +10,4 @@ urlpatterns = [
|
|||||||
path('<category_name>', category),
|
path('<category_name>', category),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns = router.urls
|
urlpatterns += router.urls
|
||||||
|
@ -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)
|
@ -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()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user