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
320
[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
540
[DjangoCon US] Testing in Django
anabalica
1
1.1k
HTTP: History & Performance
anabalica
1
550
[DUTH] Testing in Django
anabalica
4
9.6k
[PyCon US 2016] To mock or not to mock, that is the question
anabalica
0
320
[DjangoCon Europe 2016] To mock or not to mock, that is the question
anabalica
0
430
[PyLadies London 2015] How to write a good commit message
anabalica
0
400
[EuroPython 2015] Demystifying Mixins with Django
anabalica
0
360
[DjangoCon Europe 2015] Demystifying Mixins with Django
anabalica
0
320
Other Decks in Programming
See All in Programming
CloudRun, Spanner に対する負荷試験の反省と オブザーバビリティによるアプローチ
oyasumipants
1
200
Jakarta EE meets AI
ivargrimstad
0
810
Rails 1.0 のコードで学ぶ find_by* と method_missing の仕組み / Learn how find_by_* and method_missing work in Rails 1.0 code
maimux2x
1
270
ML.NETで始める機械学習
ymd65536
0
250
はじめての Go * WASM * OCR
sgash708
1
130
Amazon Bedrockマルチエージェントコラボレーションを諦めてLangGraphに入門してみた
akihisaikeda
1
180
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the benefits are huge)
lmammino
1
170
AIプログラミング雑キャッチアップ
yuheinakasaka
21
5.4k
Djangoにおける複数ユーザー種別認証の設計アプローチ@DjangoCongress JP 2025
delhi09
PRO
4
520
推しメソッドsource_locationのしくみを探る - はじめてRubyのコードを読んでみた
nobu09
2
370
【AI 自走型】Figma からデザインコーディングを行うプロンプト
tetsuro_b
0
110
楽しく向き合う例外対応
okutsu
0
760
Featured
See All Featured
Done Done
chrislema
182
16k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Documentation Writing (for coders)
carmenintech
69
4.6k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
Rails Girls Zürich Keynote
gr2m
94
13k
Visualization
eitanlees
146
15k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.2k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
How to train your dragon (web standard)
notwaldorf
91
5.9k
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