Hello guys,
I've looked at formset and model formset at Django many times, but I still can't figure the smart way to do this.
I have two models:
Group
Person
I have a queryset that contains all the persons trying to join a particular group: Person.objects.filter(wantsToJoinGroup=groupD)
Now, what I want to do, is display a page with a checkbox at the side of each person that wants to join a particular group. Those checkboxes can then be checked and then the button 'Accept to Group' is clicked. I want this to bulk add those persons to a certain group.
What I fail to understand how to do is exactly the checkbox thing. I've been trying to extend a modelform
and then make a formset
out of it, but I fail at it everytime. It seems like if I want to do a formset
with models I should use modelformset
, but that does not allow me to extend the form to add a checkbox. How can I do it?
Here is a 10-second draft on paint of what I would like to have:
So it's basically, a checkbox and a way to access the person model at the template and then a way to proccess this on the view.
Thanks in advance!
Edit: By the way, before someone suggests using ModelMultipleChoiceField
, unless there is a way to access each of the objects inside it on the template, this will not fulfill what I need to do. As far as I know, I can't iterate over the objects of ModelMultipleChoiceField on the template. Please correct me if I'm wrong!