我正在尝试为给定问题组中的每个问题创建一个表单字段。我对 python/django 很陌生,所以这可能是一个不好的方法,欢迎提出高级建议。这是我所拥有的:
模型.py:
class QuestionGroup(models.Model):
name = models.CharField(max_length = 50)
creator = models.ForeignKey(User)
modified = models.DateTimeField()
class Question(models.Model):
question_content = models.CharField(max_length = 100)
question_group = models.ForeignKey(QuestionGroup)
视图.py:
def give_feedback(request, group_id):
question_list = Question.objects.filter(question_group = group_id)
form = ResponseForm(question_list)
表格.py:
class ResponseForm(forms.Form):
def __init__(self, *args, **kwargs):
for q in args:
q.question_content = forms.CharField(max_length = 100)
我得到“'ResponseForm' 对象没有属性'_errors'”。想法?