diff --git a/db.sqlite3 b/db.sqlite3 index 20ea585..ff2ac8a 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/tkupek_elearning/elearning/admin.py b/tkupek_elearning/elearning/admin.py index 0c57a08..5d349c4 100644 --- a/tkupek_elearning/elearning/admin.py +++ b/tkupek_elearning/elearning/admin.py @@ -12,7 +12,16 @@ class QuestionAdmin(admin.ModelAdmin): OptionInline, ] + +class UserAnswerInline(admin.TabularInline): + model = UserAnswer + + +class UserAdmin(admin.ModelAdmin): + inlines = [ + UserAnswerInline, + ] + admin.site.register(Question, QuestionAdmin) admin.site.register(Setting), -admin.site.register(UserAnswer), -admin.site.register(User) +admin.site.register(User, UserAdmin) diff --git a/tkupek_elearning/elearning/models.py b/tkupek_elearning/elearning/models.py index d1e55c4..42bf6fe 100644 --- a/tkupek_elearning/elearning/models.py +++ b/tkupek_elearning/elearning/models.py @@ -46,11 +46,11 @@ class User(models.Model): class UserAnswer(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, null=False) - questionId = models.ForeignKey(Question, on_delete=models.CASCADE, null=False) + question = models.ForeignKey(Question, on_delete=models.CASCADE, null=False) answers = models.CharField(max_length=100, null=True) def __str__(self): - return str(self.user) + " - " + str(self.questionId) + return str(self.user) + " - " + str(self.question) class Meta: - unique_together = (('user', 'questionId'),) \ No newline at end of file + unique_together = (('user', 'question'),) \ No newline at end of file diff --git a/tkupek_elearning/elearning/views.py b/tkupek_elearning/elearning/views.py index 9ef3d06..dc452e8 100644 --- a/tkupek_elearning/elearning/views.py +++ b/tkupek_elearning/elearning/views.py @@ -31,13 +31,13 @@ def get_answer(request): user = User.objects.get(token=request_token) try: - user_answer = UserAnswer.objects.get(questionId=question.id, user=user.id) + user_answer = UserAnswer.objects.get(question=question.id, user=user.id) except ObjectDoesNotExist: user_answer = None if user_answer is None: user_answer = UserAnswer() - user_answer.questionId = question + user_answer.question = question user_answer.user = user user_answer.answers = request_answers user_answer.save()