Skip to content

Instantly share code, notes, and snippets.

@jubel-han
Created August 29, 2019 07:47
Show Gist options
  • Save jubel-han/0eafc70f95f0635729b510845347245d to your computer and use it in GitHub Desktop.
Save jubel-han/0eafc70f95f0635729b510845347245d to your computer and use it in GitHub Desktop.
Get Django Model Receivers
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