feature/visibility #32
@ -16,5 +16,5 @@ class CategoryModelViewSet(viewsets.ModelViewSet):
|
||||
def category(request, category_name):
|
||||
context = {}
|
||||
context['name'] = category_name
|
||||
context['tests'] = Test.objects.filter(category=category_name)
|
||||
context['tests'] = Test.objects.filter(category=category_name, invisible=False)
|
||||
return render(request, 'category.html', context)
|
@ -9,7 +9,8 @@ def home(request):
|
||||
context = {}
|
||||
# TODO replace
|
||||
#context['tests'] = Test.objects.filter(owner=request.user)
|
||||
context['tests'] = Test.objects.all
|
||||
#context['tests'] = Test.objects.all
|
||||
context['tests'] = Test.objects.filter(invisible=False)
|
||||
return render(request, 'home.html', context)
|
||||
|
||||
|
||||
|
@ -11,6 +11,10 @@
|
||||
<input id="name" type="text" name="name" value="Nowy test">
|
||||
<br>
|
||||
<br>
|
||||
<label for="invisible">Prywatny</label>
|
||||
<input type="checkbox" id="invisible" name="invisible" value="True">
|
||||
<br>
|
||||
<br>
|
||||
<label for="category">Kategoria: </label>
|
||||
<select name="category" id="category">
|
||||
<option value="JezykPolski">Język Polski</option>
|
||||
|
18
trials/migrations/0012_test_unvisible.py
Normal file
18
trials/migrations/0012_test_unvisible.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.2.9 on 2022-03-30 19:38
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trials', '0011_auto_20220123_1633'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='test',
|
||||
name='unvisible',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
18
trials/migrations/0013_rename_unvisible_test_invisible.py
Normal file
18
trials/migrations/0013_rename_unvisible_test_invisible.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.2.9 on 2022-03-30 20:42
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trials', '0012_test_unvisible'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='test',
|
||||
old_name='unvisible',
|
||||
new_name='invisible',
|
||||
),
|
||||
]
|
@ -14,6 +14,7 @@ class Test(models.Model):
|
||||
# related_name="tests"
|
||||
# )
|
||||
category = models.CharField(max_length=100)
|
||||
invisible = models.BooleanField(default=False)
|
||||
created_by = models.ForeignKey(
|
||||
"users.User",
|
||||
null=True,
|
||||
|
@ -17,6 +17,7 @@ class TestSerializer(serializers.ModelSerializer):
|
||||
"name",
|
||||
"passing_score",
|
||||
"questions",
|
||||
"invisible",
|
||||
"category",
|
||||
)
|
||||
|
||||
|
@ -27,6 +27,7 @@ def addTest(request):
|
||||
def addQuestions(request, **kwargs):
|
||||
if request.POST:
|
||||
name = request.GET.get("name")
|
||||
invisible = request.GET.get("invisible")
|
||||
passing = request.GET.get("passing")
|
||||
category = request.GET.get("category")
|
||||
number_of_questions = request.GET.get("number_of_questions")
|
||||
@ -69,7 +70,12 @@ def addQuestions(request, **kwargs):
|
||||
answer4
|
||||
]
|
||||
})
|
||||
Test.objects.create(name=name, passing_score=passing, category=category, questions=questions, user=user)
|
||||
if invisible == "True":
|
||||
Test.objects.create(name=name, passing_score=passing, category=category, questions=questions, user=user,
|
||||
invisible=True)
|
||||
else:
|
||||
Test.objects.create(name=name, passing_score=passing, category=category, questions=questions, user=user,
|
||||
invisible=False)
|
||||
return redirect('home')
|
||||
return render(request, 'addQuestions.html')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user