1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from django.db.models.query import QuerySet
#save original delete method
orrigdelete = QuerySet.delete
def showdelete(self):
#add on to delete method
for test in self:
if isinstance(test, YourObject):
raise Exception('someone tried to delete your object')
return
else:
break
#call original delete
return orrigdelete(self)
#set the queryset delete as our new method
QuerySet.delete = showdelete
|
More like this
- Middleware for using HttpOnly session cookie (including monkey patching for support for Python <2.6) by chrj 1 year, 9 months ago
- Monkey-patch Django's test client to return WSGIRequest objects by robmadole 1 year, 2 months ago
- UUIDField oriented django User by bwhittington 2 years, 9 months ago
- decorators for creating paramaterized decorators and easy monkeypatching by fish2000 2 years ago
- safe(r) monkeypatching scheme for django testing by showell 2 years, 2 months ago
Comments