This commit is contained in:
Hubert Jankowski 2021-12-13 23:22:11 +01:00
parent f939051139
commit b9f012e864
4 changed files with 114 additions and 11 deletions

View File

@ -2,7 +2,7 @@ from rest_framework.routers import DefaultRouter
from categories.views import CategoryModelViewSet from categories.views import CategoryModelViewSet
router = DefaultRouter() router = DefaultRouter(trailing_slash=False)
router.register("items", CategoryModelViewSet) router.register("items", CategoryModelViewSet)
urlpatterns = router.urls urlpatterns = router.urls

View File

@ -8,14 +8,16 @@ class QuestionManager(Manager):
def create( def create(
self, *, self, *,
answers=[], answers=[],
name=None,
test=None, test=None,
description=None, description=None,
**kwargs **kwargs
): ):
Answer = apps.get_model("answers", "Answer") Answer = apps.get_model("answers", "Answer")
instance = super().create( instance = super().create(
name=name,
test=test, test=test,
description=description, description=name,
) )
for answer in answers: for answer in answers:
Answer.objects.create( Answer.objects.create(

115
test.json
View File

@ -1,23 +1,124 @@
{ {
"name": "asd", "name": "fiz1",
"passing_score": 1, "passing_score": 3,
"questions": [ "questions": [
{ {
"name": "heja", "name": "Jaki jest najwyższy szczyt w Polsce ? ",
"description": "czesc", "description": "ramię głowicy",
"answers": [ "answers": [
{ {
"description": "hejka_answer", "description": "Rysy",
"is_correct": true
},
{
"description": "Śnieżka",
"is_correct": false "is_correct": false
}, },
{ {
"description": "hejka2_answer", "description": "Babia góra",
"is_correct": false
},
{
"description": "Tarnica",
"is_correct": false
}
]
},
{
"name": "Jaką długość ma Odra na terenie Polski ?",
"description": "złącze.",
"answers": [
{
"description": "854",
"is_correct": false
},
{
"description": "742",
"is_correct": true
},
{
"description": "772",
"is_correct": false
},
{
"description": "808",
"is_correct": false
}
]
},
{
"name": "Jaką wysokość ma śnieżka?",
"description": "kieszeń napędu",
"answers": [
{
"description": "1346",
"is_correct": false
},
{
"description": "1603",
"is_correct": true
},
{
"description": "2000",
"is_correct": false
},
{
"description": "1863",
"is_correct": false
}
]
},
{
"name": "która rzeka jest najdłuższa",
"description": "płytka drukowana .",
"answers": [
{
"description": "Warta",
"is_correct": false
},
{
"description": "Narew",
"is_correct": false
},
{
"description": "Wisła",
"is_correct": true
},
{
"description": "Bug",
"is_correct": false
}
]
},
{
"name": "Która rzeka nie przebiega przez Poznań?",
"description": "karta dźwiękowa.",
"answers": [
{
"description": "Warta",
"is_correct": false
},
{
"description": "Głuszynka",
"is_correct": false
},
{
"description": "Wierzbak",
"is_correct": false
},
{
"description": "Noteć",
"is_correct": true "is_correct": true
} }
] ]
} }
], ],
"category": { "category": {
"name": "Polski" "name": "Geografia"
} }
} }

View File

@ -31,8 +31,8 @@ class TestManager(Manager):
test=instance test=instance
) )
for answer in question["answers"]: for answer in question["answers"]:
import pdb; # import pdb;
pdb.set_trace() # pdb.set_trace()
Answer.objects.create( Answer.objects.create(
description=answer["description"], description=answer["description"],
is_correct=answer["is_correct"], is_correct=answer["is_correct"],