Skip to content Skip to sidebar Skip to footer

Form (or Formset?) To Handle Multiple Table Rows In Django

I'm working on my first Django application. In short, what it needs to do is to display a list of film titles, and allow users to give a rating (out of 10) to each film. I've been

Solution 1:

"At first, I thought this was what formsets were for, but I can't see any way to automatically iterate over the contents of a database table to produce items to go in the form, if you see what I mean."

You need to get a queryset. And you need to provide that queryset to your form as initial data. See using initial data with a formset for the code.

initial = [ list of { dictionaries }, one per form ] 

Interestingly, this is a direct feature of the model API through the values method of a queryset.

Post a Comment for "Form (or Formset?) To Handle Multiple Table Rows In Django"