Category model update
This commit is contained in:
parent
2c444c31d0
commit
b837addd84
@ -1,8 +1,13 @@
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from django.urls import path
|
||||
|
||||
from categories.views import CategoryModelViewSet
|
||||
from categories.views import CategoryModelViewSet, category
|
||||
|
||||
router = DefaultRouter(trailing_slash=False)
|
||||
router.register("items", CategoryModelViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
path('<category_name>', category),
|
||||
]
|
||||
|
||||
urlpatterns = router.urls
|
||||
|
@ -3,7 +3,17 @@ from rest_framework import viewsets
|
||||
from categories.models import Category
|
||||
from categories.serializers import CategorySerializer
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import render, redirect
|
||||
from django.template import loader
|
||||
|
||||
class CategoryModelViewSet(viewsets.ModelViewSet):
|
||||
queryset = Category.objects.all()
|
||||
serializer_class = CategorySerializer
|
||||
|
||||
@login_required
|
||||
def category(request, category_name):
|
||||
context = {}
|
||||
context['name'] = category_name
|
||||
context['tests'] = Test.objects.all(category=category_name)
|
||||
return render(request, 'category.html', context)
|
@ -25,5 +25,5 @@ urlpatterns = [
|
||||
path('questions/', include("questions.urls")),
|
||||
path('answers/', include("answers.urls")),
|
||||
path('tests/', include("trials.urls")),
|
||||
path('categories/', include("categories.urls")),
|
||||
path('category/', include("categories.urls")),
|
||||
]
|
||||
|
@ -46,16 +46,16 @@
|
||||
<a href="/test/create">Create test</a>
|
||||
<a href="/users/tests">Your tests</a>
|
||||
<p>Categories</p>
|
||||
<a href="/tests/category/1">Język polski</a>
|
||||
<a href="/tests/category/2">Język angielski</a>
|
||||
<a href="/tests/category/3">Język niemiecki</a>
|
||||
<a href="/tests/category/4">Matematyka</a>
|
||||
<a href="/tests/category/5">Informatyka</a>
|
||||
<a href="/tests/category/6">Fizyka</a>
|
||||
<a href="/tests/category/7">Chemia</a>
|
||||
<a href="/tests/category/8">Biologia</a>
|
||||
<a href="/tests/category/9">Geografia</a>
|
||||
<a href="/tests/category/10">Historia</a>
|
||||
<a href="/category/JezykPolski">Język polski</a>
|
||||
<a href="/category/JezykAngielski">Język angielski</a>
|
||||
<a href="/category/JezykNiemiecki">Język niemiecki</a>
|
||||
<a href="/category/Matematyka">Matematyka</a>
|
||||
<a href="/category/Informatyka">Informatyka</a>
|
||||
<a href="/category/Fizyka">Fizyka</a>
|
||||
<a href="/category/Chemia">Chemia</a>
|
||||
<a href="/category/Biologia">Biologia</a>
|
||||
<a href="/category/Geografia">Geografia</a>
|
||||
<a href="/category/Historia">Historia</a>
|
||||
<p>Account</p>
|
||||
<a href="/users/account">Settings</a>
|
||||
<a href="/users/logout">Logout</a>
|
||||
|
26
templates/category.html
Normal file
26
templates/category.html
Normal file
@ -0,0 +1,26 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Category - {{name}}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Tests in {{name}} category</h1>
|
||||
{% for test in tests %}
|
||||
<div class="mainTestContainer">
|
||||
<div class="mainTestName">
|
||||
{{test.name}}
|
||||
</div>
|
||||
<div class="mainTestMeta">
|
||||
Category: {{test.category}}
|
||||
</div>
|
||||
<div class="mainTestDesc">
|
||||
<!-- TODO 250 words limit-->
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus volutpat scelerisque tortor, id sodales leo finibus id. Vivamus id viverra nunc, ac faucibus metus. Nulla a mauris imperdiet sapien lobortis dapibus. Quisque ornare posuere pulvinar.
|
||||
</div>
|
||||
<div class="mainTestMeta">
|
||||
Passing score: {{test.passing_score}}
|
||||
</div>
|
||||
<button><a href="/tests/{{test.id}}/show">Start</a></button>
|
||||
</div>
|
||||
<br>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
@ -10,7 +10,7 @@
|
||||
{{test.name}}
|
||||
</div>
|
||||
<div class="mainTestMeta">
|
||||
Category: {{test.category.name}}
|
||||
Category: {{test.category}}
|
||||
</div>
|
||||
<div class="mainTestDesc">
|
||||
<!-- TODO 250 words limit-->
|
||||
|
19
trials/migrations/0006_alter_test_category.py
Normal file
19
trials/migrations/0006_alter_test_category.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 3.2.9 on 2022-01-08 18:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trials', '0005_test_category'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='test',
|
||||
name='category',
|
||||
field=models.CharField(default='Matematyka', max_length=100),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -5,12 +5,13 @@ from .managers import TestManager
|
||||
class Test(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
passing_score = models.PositiveSmallIntegerField(default=0)
|
||||
category = models.ForeignKey(
|
||||
"categories.Category",
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
related_name="tests"
|
||||
)
|
||||
# category = models.ForeignKey(
|
||||
# "categories.Category",
|
||||
# on_delete=models.SET_NULL,
|
||||
# null=True,
|
||||
# related_name="tests"
|
||||
# )
|
||||
category = models.CharField(max_length=100)
|
||||
|
||||
objects = TestManager()
|
||||
|
||||
|
@ -8,7 +8,7 @@ from categories.serializers import CategorySerializer
|
||||
class TestSerializer(serializers.ModelSerializer):
|
||||
|
||||
questions = QuestionSerializer(many=True, required=False)
|
||||
category = CategorySerializer(required=False)
|
||||
#category = CategorySerializer(required=False)
|
||||
|
||||
class Meta:
|
||||
model = Test
|
||||
|
Loading…
Reference in New Issue
Block a user