I created a form where an user can delete some preferences from the Database. Here is my view:
if 'button2' in request.POST:
instance = Keys.objects.get(id=request.POST['id'])
form2 = DeleteKey(request.POST, instance=instance)
if form2.is_valid():
profile = form.save(commit=False)
profile.key = ''
profile.save()
messages.success(request, f"Success")
return HttpResponseRedirect(request.path_info)
And the form:
class DeleteKey(forms.ModelForm):
class Meta:
model = Keys
fields = ()
def save(self, commit=True):
send = super(DeleteKey, self).save(commit=False)
if commit:
send.save()
return send
This code works, the problem is that i'm not really deleting the row from my own database, i'm just setting that field to an empty string. Is there any way to completely delete the row, instead? Thanks in advance!