Visibility property

This commit is contained in:
Piotr Kopycki 2022-03-30 23:01:39 +02:00
parent e7740dc937
commit 181877a70d
8 changed files with 52 additions and 3 deletions

View File

@ -16,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.filter(category=category_name) context['tests'] = Test.objects.filter(category=category_name, invisible=False)
return render(request, 'category.html', context) return render(request, 'category.html', context)

View File

@ -9,7 +9,8 @@ def home(request):
context = {} context = {}
# TODO replace # TODO replace
#context['tests'] = Test.objects.filter(owner=request.user) #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) return render(request, 'home.html', context)

View File

@ -11,6 +11,10 @@
<input id="name" type="text" name="name" value="Nowy test"> <input id="name" type="text" name="name" value="Nowy test">
<br> <br>
<br> <br>
<label for="invisible">Prywatny</label>
<input type="checkbox" id="invisible" name="invisible" value="True">
<br>
<br>
<label for="category">Kategoria: </label> <label for="category">Kategoria: </label>
<select name="category" id="category"> <select name="category" id="category">
<option value="JezykPolski">Język Polski</option> <option value="JezykPolski">Język Polski</option>

View 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),
),
]

View 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',
),
]

View File

@ -14,6 +14,7 @@ class Test(models.Model):
# related_name="tests" # related_name="tests"
# ) # )
category = models.CharField(max_length=100) category = models.CharField(max_length=100)
invisible = models.BooleanField(default=False)
created_by = models.ForeignKey( created_by = models.ForeignKey(
"users.User", "users.User",
null=True, null=True,

View File

@ -17,6 +17,7 @@ class TestSerializer(serializers.ModelSerializer):
"name", "name",
"passing_score", "passing_score",
"questions", "questions",
"invisible",
"category", "category",
) )

View File

@ -27,6 +27,7 @@ def addTest(request):
def addQuestions(request, **kwargs): def addQuestions(request, **kwargs):
if request.POST: if request.POST:
name = request.GET.get("name") name = request.GET.get("name")
invisible = request.GET.get("invisible")
passing = request.GET.get("passing") passing = request.GET.get("passing")
category = request.GET.get("category") category = request.GET.get("category")
number_of_questions = request.GET.get("number_of_questions") number_of_questions = request.GET.get("number_of_questions")
@ -69,7 +70,12 @@ def addQuestions(request, **kwargs):
answer4 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 redirect('home')
return render(request, 'addQuestions.html') return render(request, 'addQuestions.html')