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
310
[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
530
[DjangoCon US] Testing in Django
anabalica
1
1.1k
HTTP: History & Performance
anabalica
1
550
[DUTH] Testing in Django
anabalica
4
9.5k
[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
420
[PyLadies London 2015] How to write a good commit message
anabalica
0
400
[EuroPython 2015] Demystifying Mixins with Django
anabalica
0
350
[DjangoCon Europe 2015] Demystifying Mixins with Django
anabalica
0
320
Other Decks in Programming
See All in Programming
Rails アプリ地図考 Flush Cut
makicamel
1
110
Terraform で作る Amazon ECS の CI/CD パイプライン
hiyanger
0
140
DMMオンラインサロンアプリのSwift化
hayatan
0
300
動作確認やテストで漏れがちな観点3選
starfish719
6
990
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
210
Bedrock Agentsレスポンス解析によるAgentのOps
licux
1
270
Domain-Driven Transformation
hschwentner
2
1.9k
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
1
590
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
230
Ruby on cygwin 2025-02
fd0
0
130
Spring gRPC について / About Spring gRPC
mackey0225
0
210
DROBEの生成AI活用事例 with AWS
ippey
0
120
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Navigating Team Friction
lara
183
15k
Bash Introduction
62gerente
610
210k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.5k
KATA
mclloyd
29
14k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
29
4.6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
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