Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
[DJUGL] Signals and AppConfig
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ana Balica
October 06, 2015
Programming
0
350
[DJUGL] Signals and AppConfig
Django User Group in London meetup and my talk about "Signals and AppConfig" Rick and Morty style!
Ana Balica
October 06, 2015
Tweet
Share
More Decks by Ana Balica
See All by Ana Balica
[NDC London] HTTP: History & Performance
anabalica
0
660
[DjangoCon US] Testing in Django
anabalica
1
1.5k
HTTP: History & Performance
anabalica
1
600
[DUTH] Testing in Django
anabalica
4
9.7k
[PyCon US 2016] To mock or not to mock, that is the question
anabalica
0
370
[DjangoCon Europe 2016] To mock or not to mock, that is the question
anabalica
0
520
[PyLadies London 2015] How to write a good commit message
anabalica
0
430
[EuroPython 2015] Demystifying Mixins with Django
anabalica
0
410
[DjangoCon Europe 2015] Demystifying Mixins with Django
anabalica
0
360
Other Decks in Programming
See All in Programming
文字コードの話
qnighy
44
17k
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
510
OTP を自動で入力する裏技
megabitsenmzq
0
110
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
270
モダンOBSプラグイン開発
umireon
0
130
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
950
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
390
Ruby and LLM Ecosystem 2nd
koic
1
820
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
250
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
220
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
410
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
950
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
72
12k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
180
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Test your architecture with Archunit
thirion
1
2.2k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
100
How to Talk to Developers About Accessibility
jct
2
150
Everyday Curiosity
cassininazir
0
160
Between Models and Reality
mayunak
2
230
Code Review Best Practice
trishagee
74
20k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
980
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Transcript
SIGNALS AND APPCONFIG DJUGL October 6, 2015
@anabalica
Let’s get schwifty with !
from django.db.models.signals import post_save from django.dispatch import receiver from myapp.models
import MyModel @receiver(post_save, sender=MyModel) def my_handler(sender, **kwargs): pass # my_app/signals.py
from django.db.models.signals import pre_save from django.dispatch import receiver from myapp.models
import MyModel @receiver(pre_save, sender=MyModel) def my_handler(sender, **kwargs): pass # my_app/signals.py
Django<1.7? make sure that the module it’s in gets imported
early on so that the signal handling gets registered before any signals need to be sent
Django<1.7? make sure that the module it’s in gets imported
early on so that the signal handling gets registered before any signals need to be sent
Django<1.7? this makes your app’s models.py a good place to
put registration of signal handlers
from django.db import models from my_app import signals class MyModel(models.Model):
pass # my_app/models.py
None
CIRCULAR IMPORTS
from my_app import signals # my_app/__init__.py
None
AppConfig to the rescue
AppConfig is a registry of installed apps and available models
>>> from django.apps import apps >>> apps.get_app_config('admin').verbose_name 'Admin'
from django.apps import AppConfig class RickNMortyConfig(AppConfig): name = "rick_n_morty" verbose_name
= "Rick and Morty" # my_app/apps.py
INSTALLED_APPS = [ "my_app.apps.RickNMortyConfig", # ... ] # settings.py or
default_app_config = "my_app.apps.RickNMortyConfig" # my_app/__init__.py
None
from django.apps import AppConfig class RickNMortyConfig(AppConfig): name = "rick_n_morty" verbose_name
= "Rick and Morty” def ready(self): from my_app import signals # my_app/apps.py
• Loads the settings • Sets up logging • Initializes
the application registry
• Imports each item from INSTALLED_APPS • Imports the models
submodule if exists • Runs the ready() method of each app config
None