1π
β
I would not do anything unless the form is valid:
if form.is_valid():
d_data = Information.objects.filter(name=form.cleaned_data.get('full_name'))
if len(d_data) == 1:
d_data.delete()
d_data = None
else:
d_data = None
context = {
'form': form,
'd_data': d_data,
}
return render(request, 'delete.html', context)
Note: I set d_data
to None
after itβs been deleted.
On wheter to use d_data.count()
or len(d_data)
, please see this
π€Pynchia
Source:stackexchange.com