-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(follows): delete object-orphaned Follows...
... based on Django pre_delete signal
- Loading branch information
1 parent
b894d76
commit d06e7e2
Showing
3 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
from actstream.models import Follow | ||
|
||
|
||
def delete_orphaned_follows(sender, instance=None, **kwargs): | ||
""" | ||
Clean up Follow objects that refer to a Django object that's being deleted | ||
""" | ||
if str(sender._meta) == 'migrations.migration': | ||
return | ||
|
||
try: | ||
Follow.objects.for_object(instance).delete() | ||
except ImproperlyConfigured: # raised by actstream for irrelevant models | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters