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
290
[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
480
[DjangoCon US] Testing in Django
anabalica
1
990
HTTP: History & Performance
anabalica
1
520
[DUTH] Testing in Django
anabalica
4
9.5k
[PyCon US 2016] To mock or not to mock, that is the question
anabalica
0
290
[DjangoCon Europe 2016] To mock or not to mock, that is the question
anabalica
0
360
[PyLadies London 2015] How to write a good commit message
anabalica
0
380
[EuroPython 2015] Demystifying Mixins with Django
anabalica
0
320
[DjangoCon Europe 2015] Demystifying Mixins with Django
anabalica
0
290
Other Decks in Programming
See All in Programming
"noncopyable types" の使いどころについて考えてみた
andpad
0
130
sqlcを利用してsqlに型付けを
kamiyam
0
220
ファーストペンギンBot @Qiita Hackathon 2024 予選
dyson_web
0
210
GitHub Copilot Workspace で我々のアプリ開発がどう変わるのか?
shuyakinjo
0
840
API Platform for Laravel
dunglas
1
1.2k
Go製CLIツールGatling Commanderによる負荷試験実施の自動化
okmtz
3
640
Iteratorでページネーションを実現する
sonatard
3
700
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
3
390
Progressive Web Apps for Rails developers
siaw23
2
520
AWS認定資格を受験するにあたり、気づいたこと・実践していたことのまとめ
satoshi256kbyte
1
120
tsconfig.jsonの最近の新機能 ファイルパス編
uhyo
6
1.3k
グローバルなソフトウェアテスト組織における課題と戦略 / Challenges and Strategies in a Global Software Testing Organization #mf_techday
imtnd
0
220
Featured
See All Featured
Teambox: Starting and Learning
jrom
131
8.7k
Visualization
eitanlees
143
15k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.1k
Ruby is Unlike a Banana
tanoku
96
11k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Designing for humans not robots
tammielis
249
25k
For a Future-Friendly Web
brad_frost
174
9.3k
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.7k
How STYLIGHT went responsive
nonsquared
94
5.1k
The Mythical Team-Month
searls
218
43k
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