[Django]-Form (or Formset?) to handle multiple table rows in Django

3πŸ‘

βœ…

β€œ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.

πŸ‘€S.Lott

0πŸ‘

I have found my answer, using modelformset_factory instead formset_factory solves the problem, Thanks…

πŸ‘€juanefren

Leave a comment