AppConfig.ready() in Django
AppConfig.ready():-
- This method subclasses can override to perform initialization tasks such as registering signals.
- It is called as soon as the registry is fully populated.
- Although you can not import models at the module-level where AppConfig classes are defined, you can import them in ready(), using either an import statement or get_model().
- If you are registering model signals, you can refer to the sender by its string label instead of using the model class itself.
Note:
- In the usual initialization process, the ready method is only called once by Django. But in some corner cases, particularly in tests which are fiddling with installed applications, ready might be called more than once.
- In this case, either write idempotent methods, or put a flag on your AppConfig classes to prevent re-running code which should be executed exactly one time..
Comments
Post a Comment