Issue displaying question for answer in

I ran into a problem I have questions that are related to items_buy_id , there are also choices that are related to question_id questions

Questions items_buy_id It turns out to connect

And with the choice you will not contact as it should


from django.db import models
from datetime import datetime
from phonenumber_field.modelfields import PhoneNumberField
from django_resized import ResizedImageField
from email.policy import default
from django.utils.translation import gettext_lazy

class Items_buy(models.Model):

    class Meta:
        db_table = 'items_buy'
        verbose_name = 'Телефон который покупаем'
        verbose_name_plural = 'Телефоны которые покупаем'

    image_phone = ResizedImageField(size=[100,100], upload_to='for_sell/',verbose_name='Фотография модели телефона')
    model_produkt = models.TextField(max_length=80, verbose_name='Модель продукта ')
    text = models.TextField(max_length=500, verbose_name='Текст')
    max_prise_iphone = models.FloatField(verbose_name='Максимальная цена telefoha')
    image_phone_for_buy_bord = ResizedImageField(size=[100,100],upload_to='for_sell/',verbose_name='Фотография модели телефона ha prodazy')

    def __str__(self):
        return self.model_produkt

class Question(models.Model):

    class Meta:
        db_table = 'question'
        verbose_name = 'Вопрос к телефону'
        verbose_name_plural = 'Вопросы к телефону'

    items_buy_id = models.ForeignKey(Items_buy, on_delete=models.RESTRICT)
    title = models.CharField(max_length=150,verbose_name='Заголовок вопросa')
    question_text =models.TextField(max_length=100, verbose_name='Заголовок вопросa text')
    max_prise_qustion = models.FloatField(verbose_name='Максимальная цена')

    def __str__(self):
           return self.title

class Choice(models.Model):

    class Meta:
        db_table = 'choice'
        verbose_name = 'Выбор ответа'
        verbose_name_plural = 'Выбор ответов'
    #items_buy_id = models.ForeignKey(Items_buy, on_delete=models.RESTRICT)
    question_id = models.ForeignKey(Question, on_delete=models.RESTRICT)
    title = models.CharField(max_length=1000, verbose_name='Заголовок выбора')
    points = models.FloatField(verbose_name='Цена ответа')
    #lock_other = models.BooleanField(default=False, verbose_name='Смотреть другой вариант ответа')

    def __str__(self):
           return self.title


from django.urls import path, re_path
from . import views

urlpatterns = [
    path('',views.home, name ='home'),
    path('sell_iphone/', views.sell_iphone, name = 'sell_iphone'),
    path('sell_iphone_page/<int:pk>/', views.sell_iphone_page, name= 'sell_iphone_page'),
    path("getqestion/<int:pk>/", views.getqestion, name = 'getqestion'),


My html

{% load static %}
{% block content %}
    <link rel="stylesheet" href="{% static 'css/qestion.css' %}" type="text/css">
    {% include 'navbar.html' %}
    <div class="bar">
        {% for question in test %}
            <div class="bar_infor_bar">
                <div class="bar_infor_bar_title">{{question.title}} </div>
                <div class="wraper_sell_in_line_img_class2_qestion_text">{{question.question_text}}</div>
                {% for choiceses in choice %}
                    <div class="bar_infor_button_nav">
                        <button class="bar_infor_button">{{choiceses.title}}</button>
                {% endfor %}
        {% endfor %}
{% endblock %}  


from django.shortcuts import render, redirect
from .models import Items_buy, Question, Choice, Answer, Orders
from django.core.paginator import Paginator,PageNotAnInteger,EmptyPage

def home(request):
    return render(request, 'home.html')

def sell_iphone(request):
    limit =  request.GET.get('limit')

    if limit == None:
        limit = 40
    limit = int(limit)   

    iphone = Items_buy.objects.filter()
    count = iphone.count()
    page = request.GET.get('page')
    paginator = Paginator(iphone, 1)
        iphone =
    except PageNotAnInteger:
        page = 1 
        iphone =
    except EmptyPage:
        page = paginator.num_pages
        iphone =

    #pages = list(range(1, (paginator.num_pages + 1)))
    iphone = Items_buy.objects.all()
    #iphone = iphone[0:limit]
    context = {'iphone':iphone, 'count':count, 'paginator':paginator, }
    return render(request, 'sell_iphone.html', context)
def sell_iphone_page(request,pk ):
    iphones = Items_buy.objects.filter(id=pk)
    #question = Question.objects.all()
    context = {'iphones':iphones, }
    return render(request, 'sell_iphone_page.html', context)

`def getqestion( request, pk):
    test = Question.objects.filter(items_buy_id = pk) 
    choice = Choice.objects.filter(question_id = pk)
    context = {'test':test,'choice':choice}
    return render(request, 'getqestion.html', context)`

I'm having a problem with the def getqestion function. I linked the question to the product, but the answer to the question didn't work at all

When using select choice = Choice.objects.filter(question_id = pk) enter image description here

When using select choice = Choice.objects.all() enter image description here

When using select choice = Choice.objects.filter(id = pk) enter image description here

And you need 1.test1 to include: da, net, HY TAKOE

And 1.test2 included: 2,1,3

Thanks in advance to anyone who can suggest how to do this!!!

In my case it helped

class getqestion(generic.DetailView):

model = Items_buy
template_name = 'getqestion.html'   
context_object_name = 'testing'


<div> {% for testings in testing.question_set.all %} <h1>{{testings.titles}}</h1> <h3>{{testings.question_text}}</h3> {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} {% csrf_token %} <form action="{% url 'vote'}" method="post"> {% for choice in testings.choice_set.all %} <input type="checkbox" name="choice" id="choice{{ forloop.counter }}" value="{{ }}"> <label for="choice{{ forloop.counter }}">{{choice.title}}</label> {% endfor %} {% endfor %} </div> <input type="submit" value="vote"> </form>
Back to Top