Не получается добавить проверку

Помогите, пожалуйста, правильно сделать проверку на наличие контента на странице. То есть если в базе нету вопросов, то форма не должна отображаться на странице pic VIEW

def quiz(requests):
    AnswerFormset = formset_factory(AnswerForm, max_num=3, min_num=3)
    if requests.method == "GET":

        questions = Question.objects.order_by('?')[:3]
        formset = AnswerFormset(initial=[{'question': question} for question in questions])

    else:
        formset = AnswerFormset(requests.POST)
        if formset.is_valid():
            correct, incorrect = 0, 0
            for data in formset.cleaned_data:
                if data['question'].is_true == data['answer']:
                    correct += 1
                else:
                    incorrect += 1
            return render(requests, 'quiz/result.html', {'correct': correct, 'incorrect': incorrect})

    return render(requests, 'quiz/list_quiz.html', {'formset': formset})

FORM

class AnswerForm(forms.Form):
    question = forms.ModelChoiceField(queryset=Question.objects.all(), required=True, widget=forms.HiddenInput)
    answer = forms.TypedChoiceField(choices=[(True, 'True'), (False, 'False')], widget=forms.RadioSelect,
                                    coerce=lambda x: x == 'True', )

    def __init__(self, *args, **kwargs):
        super(AnswerForm, self).__init__(*args, **kwargs)
        if 'question' in self.initial:  # hack
            self.question_text = self.initial['question'].question

    def clean_question(self):
        data = self.cleaned_data['question']
        self.question_text = data.question  # hack
        return data

Ответы (2 шт):

Автор решения: Alecs Fly

Ну скорее всего вам нужна функция которая возвращает True или False зависимости от того пустой queryset вы получаете от бд или нет. Потом в шаблонах с помощью тега будет показываться ваша форма или нет в зависимости что вернет функция

{% if вызов функции %}
   {{ form }}
{% endif %}
→ Ссылка
Автор решения: Hey it's Serge

В общем разобрался сам, нужно было просто добавить дополнительную проверку и рендирить шаблон, где нет вопросов.

if len(Question.objects.all()) < 3:
                 return render(request, 'quiz/template_no_questions.html',)


def quiz(request):
        AnswerFormset = formset_factory(AnswerForm, max_num=3, min_num=3)
        if request.method == "GET":
            if len(Question.objects.all()) < 3:
                return render(request, 'quiz/template_no_questions.html',)
            questions = Question.objects.order_by('?')[:3]
            formset = AnswerFormset(initial=[{'question': question} for question in questions])
        else:
            formset = AnswerFormset(request.POST)
            if formset.is_valid():
                correct, incorrect = 0, 0
                for data in formset.cleaned_data:
                    if data['question'].is_true == data['answer']:
                        correct += 1
                    else:
                        incorrect += 1
                return render(request, 'quiz/result.html', {'correct': correct, 'incorrect': incorrect})
    
        return render(request, 'quiz/list_quiz.html', {'formset': formset})
→ Ссылка