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
Ana Balica
October 06, 2015
Programming
0
330
[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
570
[DjangoCon US] Testing in Django
anabalica
1
1.2k
HTTP: History & Performance
anabalica
1
570
[DUTH] Testing in Django
anabalica
4
9.6k
[PyCon US 2016] To mock or not to mock, that is the question
anabalica
0
340
[DjangoCon Europe 2016] To mock or not to mock, that is the question
anabalica
0
460
[PyLadies London 2015] How to write a good commit message
anabalica
0
410
[EuroPython 2015] Demystifying Mixins with Django
anabalica
0
380
[DjangoCon Europe 2015] Demystifying Mixins with Django
anabalica
0
340
Other Decks in Programming
See All in Programming
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
3
450
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
3
750
生成AI時代のコンポーネントライブラリの作り方
touyou
1
170
#QiitaBash MCPのセキュリティ
ryosukedtomita
1
990
AIともっと楽するE2Eテスト
myohei
0
330
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
51
33k
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
160
Code as Context 〜 1にコードで 2にリンタ 34がなくて 5にルール? 〜
yodakeisuke
0
120
NPOでのDevinの活用
codeforeveryone
0
810
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
1
4.7k
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
630
PipeCDのプラグイン化で目指すところ
warashi
1
270
Featured
See All Featured
How GitHub (no longer) Works
holman
314
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Side Projects
sachag
455
42k
The World Runs on Bad Software
bkeepers
PRO
69
11k
Gamification - CAS2011
davidbonilla
81
5.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
5
270
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
60k
Documentation Writing (for coders)
carmenintech
72
4.9k
It's Worth the Effort
3n
185
28k
Speed Design
sergeychernyshev
32
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