0

I have a model called Question and this model allow users to create new questions. A user creates 10 question . How can I populate 10 forms with the question inside? Because I know I can populate a form with single object but when I try to populate 10 objects . The reason I want to populate 10 objects is to allow the user to edit his question

How could this be done?

thank you ,

I receive this error

'QuerySet' object has no attribute '_meta'

models.py

class Question(models.Model):
    question= models.CharField(max_length=500)
    user = models.ForeignKey(User)

forms

class QuestionForm(forms.ModelForm):
    class Meta:
        model = Question
        fields = ('question',) 

views

def DisplayAll(request):
    q = Question.objects.filter(user=request.user)
    form = QuestionForm(instance=q)
    return render(request,'question.html',{'form':form })

forms.py

{% for f in form %}
{{form}}
{% endfor %}
4

1 回答 1

1

您正在寻找表单集

表单集是用于在同一页面上处理多个表单的抽象层。最好将其与数据网格进行比较。

于 2013-07-04T14:32:13.877 回答