6
6
from rest_framework .response import Response
7
7
from rest_framework import status
8
8
9
- from diary .models import Diary , Sentences , Quizs
9
+ from diary .models import Diary , Sentences , Keywords , Questions
10
10
from diary .serializers import *
11
11
from users .models import User
12
12
@@ -54,9 +54,10 @@ def post(self, request):
54
54
sentence = Sentences .objects .create (sentence = content , diary = diary )
55
55
56
56
memory = TextRank (content = content )
57
- question , answer = make_quiz (memory , keyword_size = 5 )
57
+ question , keyword = make_quiz (memory , keyword_size = 5 )
58
58
59
- Quizs .objects .bulk_create ([Quizs (question = q , answer = a , sentence = sentence ) for q , a in zip (question , answer )])
59
+ keywords = Keywords .objects .bulk_create ([Keywords (keyword = k , sentence = sentence ) for k in keyword ])
60
+ Questions .objects .bulk_create ([Questions (question = q , keyword = k ) for q , k in zip (question , keywords )])
60
61
61
62
return JsonResponse ({'isSuccess' : True , 'result' : SentenceSimpleSerializer (sentence ).data }, status = status .HTTP_201_CREATED )
62
63
@@ -87,9 +88,10 @@ def post(self, request):
87
88
sentence = Sentences .objects .create (sentence = content , diary = diary )
88
89
89
90
memory = TextRank (content = content )
90
- question , answer = make_quiz (memory , keyword_size = 5 )
91
+ question , keyword = make_quiz (memory , keyword_size = 5 )
91
92
92
- Quizs .objects .bulk_create ([Quizs (question = q , answer = a , sentence = sentence ) for q , a in zip (question , answer )])
93
+ keywords = Keywords .objects .bulk_create ([Keywords (keyword = k , sentence = sentence ) for k in keyword ])
94
+ Questions .objects .bulk_create ([Questions (question = q , keyword = k ) for q , k in zip (question , keywords )])
93
95
94
96
return JsonResponse ({'isSuccess' : True , 'result' : SentenceSimpleSerializer (sentence ).data }, status = status .HTTP_201_CREATED )
95
97
except Diary .DoesNotExist :
@@ -127,13 +129,21 @@ def get(self, request):
127
129
return JsonResponse ({'isSuccess' : False , 'message' : '해당 일기를 찾을 수 없습니다.' }, status = status .HTTP_404_NOT_FOUND )
128
130
129
131
sentences = diary .sentences .all ()
130
- quizs = []
132
+
133
+ q = []
134
+ a = []
131
135
132
136
for sentence in sentences :
133
- quizs .extend (sentence .quizs .all ())
134
-
135
- serializer = QuizSerializer (quizs , many = True )
137
+ keywords = sentence .keywords .all ()
138
+ a .extend (keywords )
139
+ for keyword in keywords :
140
+ questions = keyword .questions .all ()
141
+ q .extend (questions )
142
+
143
+ result = []
144
+ for question_obj , keyword_obj in zip (q , a ):
145
+ result .append ({"Q" : question_obj .question , "A" : keyword_obj .keyword })
136
146
137
- return JsonResponse (serializer . data , safe = False , status = status .HTTP_200_OK )
147
+ return JsonResponse ({ 'result' : result } , status = status .HTTP_200_OK )
138
148
139
149
return JsonResponse (serializer .errors , status = status .HTTP_400_BAD_REQUEST )
0 commit comments