[Answer]-Form of a list of instances

1👍

You can use a ModelChoiceField or a ModelMultipleChoiceField.

class MyForm(forms.Form):
my_list_of_instances = forms.ModelMultipleChoiceField(queryset = MyModel.objects.all().order_by('-id')[:10], widget=forms.CheckboxSelectMultiple)

This should generate a list of checkbox with your last 10 instances created.

With this you have your form ready to receive your input…just point your action to your view.

Edit:
In case you want to have several forms, one for each instance, you can work with Formsets. You would not get the checkboxes tho…you would get any change applied to your instances. If you want to have both (checkboxes and formsets) you can use both suggestions, using the checkbox values sent to the server to filter the formsets you are going to save.

Leave a comment