class QuizList(APIView):
renderer_classes = [TemplateHTMLRenderer]
template_name = 'adminView.html'
def get(self, request):
queryset = Quiz.objects.all()
return Response({'quiz': queryset})
class AnswerList(APIView):
renderer_classes = [TemplateHTMLRenderer]
template_name = 'adminView.html'
def get(self, request):
queryset = Answer.objects.all()
return Response({'answer': queryset})
class QuestionList(APIView):
renderer_classes = [TemplateHTMLRenderer]
template_name = 'adminView.html'
def get(self, request):
queryset = Question.objects.all()
return Response({'question': queryset})In the above snippet, I am able to list the very first class "QuizView" on my web page. But other than that, when I am trying to add other APIViews, they are simply not happening. Below is the HTML template:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin View</title>
</head>
<body>
<ul>
{% for quizez in quiz %}
<a href="" onclick="">{{ quizez.name }}</a>
{% endfor %}
</ul>
<ul>
{% for questions in question %}
<li>{{ questions.label }}</li>
{% endfor %}
</ul>
<ul>
{% for answers in answer %}
<li>{{ answer.text }}</li>
{% endfor %}
</ul>
</body>
</html>I tried to put all the for loops within a single "ul", but even that didn't work. Please help.
Thank you
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1895937763.9174288.1575484276499%40mail.yahoo.com.
from rest_framework import serializers
from .models import Quiz, Question, QuizTakers, Answer, User
from django.contrib.auth import authenticate, login
class userSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = 'email'
class QuizSerializer(serializers.ModelSerializer):
class Meta:
model = Quiz()
fields = ('name', 'questions_count', 'description', 'created', 'roll_out')
def createQuestion(self, validated_data):
return Question().objects.create_question(**validated_data)
class AnswerSerializer(serializers.ModelSerializer):
class Meta:
model = Answer()
fields = ('question', 'text', 'is_correct')
class QuestionSerializer(serializers.ModelSerializer):
class Meta:
model = Question()
fields = ('quiz', 'label', 'order')
class QuizTakerSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = QuizTakers()
fields = ('user', 'quiz', 'correct_answers', 'completed', 'timestamp')
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2093858531.9194413.1575486878110%40mail.yahoo.com.