small improvement to admin panel (userAnswer is now in user)
This commit is contained in:
parent
4a1716de73
commit
a6589b9e84
4 changed files with 16 additions and 7 deletions
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
|
@ -12,7 +12,16 @@ class QuestionAdmin(admin.ModelAdmin):
|
||||||
OptionInline,
|
OptionInline,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class UserAnswerInline(admin.TabularInline):
|
||||||
|
model = UserAnswer
|
||||||
|
|
||||||
|
|
||||||
|
class UserAdmin(admin.ModelAdmin):
|
||||||
|
inlines = [
|
||||||
|
UserAnswerInline,
|
||||||
|
]
|
||||||
|
|
||||||
admin.site.register(Question, QuestionAdmin)
|
admin.site.register(Question, QuestionAdmin)
|
||||||
admin.site.register(Setting),
|
admin.site.register(Setting),
|
||||||
admin.site.register(UserAnswer),
|
admin.site.register(User, UserAdmin)
|
||||||
admin.site.register(User)
|
|
||||||
|
|
|
@ -46,11 +46,11 @@ class User(models.Model):
|
||||||
|
|
||||||
class UserAnswer(models.Model):
|
class UserAnswer(models.Model):
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE, null=False)
|
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)
|
answers = models.CharField(max_length=100, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.user) + " - " + str(self.questionId)
|
return str(self.user) + " - " + str(self.question)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = (('user', 'questionId'),)
|
unique_together = (('user', 'question'),)
|
|
@ -31,13 +31,13 @@ def get_answer(request):
|
||||||
user = User.objects.get(token=request_token)
|
user = User.objects.get(token=request_token)
|
||||||
|
|
||||||
try:
|
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:
|
except ObjectDoesNotExist:
|
||||||
user_answer = None
|
user_answer = None
|
||||||
|
|
||||||
if user_answer is None:
|
if user_answer is None:
|
||||||
user_answer = UserAnswer()
|
user_answer = UserAnswer()
|
||||||
user_answer.questionId = question
|
user_answer.question = question
|
||||||
user_answer.user = user
|
user_answer.user = user
|
||||||
user_answer.answers = request_answers
|
user_answer.answers = request_answers
|
||||||
user_answer.save()
|
user_answer.save()
|
||||||
|
|
Loading…
Reference in a new issue