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 %}

1 Answer 1

1

You are looking for the formsets

A formset is a layer of abstraction to work with multiple forms on the same page. It can be best compared to a data grid.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.