Created
August 29, 2019 07:47
-
-
Save jubel-han/0eafc70f95f0635729b510845347245d to your computer and use it in GitHub Desktop.
Get Django Model Receivers
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
from django.db.models import signals | |
# list_model_receivers(Model_Name) | |
# e.g. | |
# >>> list_model_receivers(MyModel) | |
def list_model_receivers(model): | |
for k, v in vars(signals).items(): | |
if not isinstance(v, signals.ModelSignal): | |
continue | |
receivers = getattr(signals, k)._live_receivers(model) | |
if not receivers: | |
continue | |
receivers = [f'{r.__module__}.{r.__name__}' for r in receivers] | |
print(k, receivers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment