django-safedelete
django-safedelete copied to clipboard
model.objects.all() returns deleted objects
Was wondering if anyone else is having this issue where .all()
is returning deleted objects as well. To bypass for now i have to query for .exclude(deleted__isnull=False)
on my model objects.
Could you provide some more information?
Hi @AndreasBackx, in my project I have an user model which I extended from Django's default user model. In my model, I implement SOFT_DELETE_CASCADE
. When I delete a user using User.delete()
, the deleted column in the user table is replaced with the datetime of when the user was deleted. However, in my view file, when I query User.objects.all()
the deleted user still gets returned along with all the other objects.
Did you overwrite the manager of your model without inheriting from SafeDeleteManager
?
This is what I have in my user.py model and view files: https://gist.github.com/rlwy/b7444d890bc9aa8ad90876b5388ae876
AbstractUser
has a custom manager. You should create your own manager which inherits from both UserManager
and SafeDeleteManager
and set it on your model.
Hello @Gagaro. I'm getting the same error, Could you please help me with this.
I have the same model as rlwy
I can use this to override but I'm not pretty sure,
class CustomManager(models.Manager):
def get_queryset(self):
return super(CustomManager, self).get_queryset().filter(delete=None)
class User(models.Model):
# Blah blah
objects = CustomManager()
I want to implement safedelete package in my project.
Your manager needs to inherits from both UserManager
(from django.contrib.auth
) and SafeDeleteManager
.