Delete () instance

In my opinion:

def delete_payment(request, id):
    thePayment = Payment.objects.filter(id=id)
    thePayment.delete()
    return HttpResponseRedirect('/invoices/open/')

In my model:

def delete(self, *args, **kwargs):
    raise Exception('foo')
    super(Payment, self).delete(*args, **kwargs)

I find that an exception does not occur unless I remove the instance from the administrator view. That is, I cannot get delete () to be called correctly if I use my own view.

+3
source share
1 answer

Manager.filter()returns a QuerySet, not a Model. QuerySet.delete()It doesn’t Model.delete(), but rather works directly with the database.

+4
source

Source: https://habr.com/ru/post/1777377/


All Articles