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
250
[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
370
[DjangoCon US] Testing in Django
anabalica
1
860
HTTP: History & Performance
anabalica
1
470
[DUTH] Testing in Django
anabalica
4
9.3k
[PyCon US 2016] To mock or not to mock, that is the question
anabalica
0
250
[DjangoCon Europe 2016] To mock or not to mock, that is the question
anabalica
0
280
[PyLadies London 2015] How to write a good commit message
anabalica
0
340
[EuroPython 2015] Demystifying Mixins with Django
anabalica
0
270
[DjangoCon Europe 2015] Demystifying Mixins with Django
anabalica
0
250
Other Decks in Programming
See All in Programming
どうしてこうなった命名集 ~🔥編~ / OOC 2024 LT
pictiny
5
3.9k
1BRC--Nerd Sniping the Java Community
gunnarmorling
0
300
Folding Cheat Sheet #2
philipschwarz
PRO
0
110
スクラムガイドのスプリントレトロスペクティブを改めて読みかえしてみた / Re-reading the Sprint Retrospective Section in the Scrum Guide
mackey0225
3
310
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
200
チーム力を高めるスクラム実践法:カンバン公開と課題攻略について - ニフティのスクラムトーク Vol. 2 - NIFTY Tech Talk #18
niftycorp
PRO
1
110
try! Swift Tokyo 2024のLT枠に採択されたプロポーザルを出すときに考えていたこと
ski
0
330
フロントエンドパフォーマンス 入門
shouta2
7
1.6k
1인 개발자로 행복하게 살기 - GDG 송도 헬로월드 2024
benjaminkim
1
5.5k
Semantic search with Django and pgvector
pauloxnet
0
220
スクラムチームと認知負荷 - ニフティのスクラムトーク Vol2. / NIFTY Tech Talk #18
niftycorp
PRO
1
120
二郎系ラーメンのコールで学ぶ AST 解析
memory1994
PRO
7
1.6k
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
124
32k
Fontdeck: Realign not Redesign
paulrobertlloyd
75
4.9k
Infographics Made Easy
chrislema
237
18k
The Art of Programming - Codeland 2020
erikaheidi
41
12k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
Scaling GitHub
holman
457
140k
Learning to Love Humans: Emotional Interface Design
aarron
266
39k
Creatively Recalculating Your Daily Design Routine
revolveconf
209
11k
Building Effective Engineering Teams - LeadDev
addyosmani
26
1.8k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
240
1.2M
Design by the Numbers
sachag
274
18k
Designing for Performance
lara
601
67k
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