我创建了一个民意调查应用,其中models.py中有两个类叫做问题和选择。问题意味着投票的问题,选择意味着每个问题的选择供用户选择和投票。
models.py
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length= 100)
pub_date = models.DateTimeField('Date Is Published')
image = models.ImageField(upload_to="Question_Image", blank=True)
def __str__(self):
return self.question_text
class Choice(models.Model):
choice_text = models.CharField(max_length= 200)
votes = models.IntegerField(default= 0)
image2 = models.ImageField(upload_to="Question_Image2", blank=True)
question = models.ForeignKey(Question, on_delete= models.CASCADE)
def __str__(self):
return self.choice_text
def vote_range(self):
return range(0, self.votes)
admin.py
from django.contrib import admin
from .models import Question,Choice
admin.site.register(Question)
admin.site.register(Choice)
现在,我想为每个问题添加课程“评论”并注册评论字段,以便任何用户都可以通过details.html输入评论,评论应该显示在results.html中