Python 如何将BooleanField从模型引用到模板
请帮忙 我制作了两种型号:问答式: 徖Python 如何将BooleanField从模型引用到模板,python,templates,view,model,boolean,Python,Templates,View,Model,Boolean,请帮忙 我制作了两种型号:问答式: 徖 from django.db import models from django.utils import timezone class Question(models.Model): question_text = models.CharField(max_length=400) time_pub = models.DateTimeField() class Answer(models.Model): question_Answe
from django.db import models
from django.utils import timezone
class Question(models.Model):
question_text = models.CharField(max_length=400)
time_pub = models.DateTimeField()
class Answer(models.Model):
question_Answer = models.ForeignKey(Question, on_delete= models.CASCADE)
answer_text = models.CharField(max_length=100)
true_answer = models.BooleanField(default = False)
from django.shortcuts import render
from django.http import HttpResponse
from .models import *
import random
# Create your views here.
def index(request):
bocauhoi = Question.objects.all()
rand = random.choice(bocauhoi)
traloi = rand.answer_set.all()
return render(request,"Piapp/index.html",{"random":rand,"tl":traloi})
def Result(request):
kqua =Answer.true_answer()
return render(request,"Piapp/result.html",{"kq":kqua})
和my Views.py如下:
徖
from django.db import models
from django.utils import timezone
class Question(models.Model):
question_text = models.CharField(max_length=400)
time_pub = models.DateTimeField()
class Answer(models.Model):
question_Answer = models.ForeignKey(Question, on_delete= models.CASCADE)
answer_text = models.CharField(max_length=100)
true_answer = models.BooleanField(default = False)
from django.shortcuts import render
from django.http import HttpResponse
from .models import *
import random
# Create your views here.
def index(request):
bocauhoi = Question.objects.all()
rand = random.choice(bocauhoi)
traloi = rand.answer_set.all()
return render(request,"Piapp/index.html",{"random":rand,"tl":traloi})
def Result(request):
kqua =Answer.true_answer()
return render(request,"Piapp/result.html",{"kq":kqua})
from django.db import models
from django.utils import timezone
class Question(models.Model):
question_text = models.CharField(max_length=400)
time_pub = models.DateTimeField()
class Answer(models.Model):
question_Answer = models.ForeignKey(Question, on_delete= models.CASCADE)
answer_text = models.CharField(max_length=100)
true_answer = models.BooleanField(default = False)
from django.shortcuts import render
from django.http import HttpResponse
from .models import *
import random
# Create your views here.
def index(request):
bocauhoi = Question.objects.all()
rand = random.choice(bocauhoi)
traloi = rand.answer_set.all()
return render(request,"Piapp/index.html",{"random":rand,"tl":traloi})
def Result(request):
kqua =Answer.true_answer()
return render(request,"Piapp/result.html",{"kq":kqua})
我想检查字段:true\u回答并在新模板中打印。
如何处理:如果为真,则模板中的“您的答案为真”和“您的答案为错”。
请帮忙强>