filter by category

This commit is contained in:
Hubert Jankowski 2022-01-09 22:29:40 +01:00
parent b837addd84
commit bc6d973bf3
2 changed files with 3 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)