Reputation: 4313
I override delete
method (have made object non-deleteable and set 'active' field to false) in custom QuerySet
in custom ModelManager
.
Is there any way to ignore custom manager in admin panel so I can actually delete objects from there?
First thought: I can specify another name for custom Manager. But now it's treated as default... And how to bypass obj.delete()?
Solution for first problem is to add custom manager alongside with default:
objects = models.Manager()
active_manager = EventManager()
Solution to second problem is to add param to the custom delete
method:
def delete(self, *args, **kwargs):
force = kwargs.pop('force', False)
...
Upvotes: 0
Views: 278
Reputation:
You can add parameter to your custom delete
method. for example:
def delete(self, super=True):
if super:
return self.get_queryset().delete()
else:
# Your custom code here
Upvotes: 1