Skip to content
Snippets Groups Projects
Commit 6e5add47 authored by sandroroux's avatar sandroroux
Browse files

Adds retire_user mixin.

parent e0078abe
Branches
Tags release-2021-09-02-16.48
No related merge requests found
...@@ -12,3 +12,25 @@ class DeprecatedModelMixin(object): ...@@ -12,3 +12,25 @@ class DeprecatedModelMixin(object):
Override to kill usage of this model. Override to kill usage of this model.
""" """
raise TypeError("This model has been deprecated and should not be used.") raise TypeError("This model has been deprecated and should not be used.")
class DeletableByUserValue(object):
"""
This mixin allows inheriting models to delete instances of the model
associated with some user.
"""
@classmethod
def delete_by_user_value(cls, value, field):
"""
Deletes instances of this model where ``field`` equals ``value``.
e.g.
``delete_by_user_value(value='learner@example.com', field='email')``
Returns True if any instances were deleted.
Returns False otherwise.
"""
filter_kwargs = {field: value}
num_deleted_records, _ = cls.objects.filter(**filter_kwargs).delete()
return num_deleted_records > 0
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment