Skip to content Skip to sidebar Skip to footer

How Can I Filter Queryset By Checked Form Checkboxes In Django?

I need to update the model according to the marked checkboxes in the django shape How can I get only some of the table fields in a query the 'checked' line should be updated throug

Solution 1:

You can get all the fields using ".values ()" for the queryset, and to use it with foreignKey, you need to explicitly specify the model fields:

f = tableDashFilter(request.GET, queryset=moIn.objects.values('id','date','ts','pl','rem','comment','checked','staffer__username','checkedUser__username'))

"Value" from the input, it is also going to be obtained through: Since there can be several values (marked checkboxes), there will be a ".getlist"

checkID = request.POST.getlist('checked')

querySet filter:

f.qs.filter(id__in=checkID).update(checked=True, checkedUser=request.user)

in the html template through the loop, iterate over and insert into the input value of the model id


Post a Comment for "How Can I Filter Queryset By Checked Form Checkboxes In Django?"