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
300
[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
500
[DjangoCon US] Testing in Django
anabalica
1
1k
HTTP: History & Performance
anabalica
1
530
[DUTH] Testing in Django
anabalica
4
9.5k
[PyCon US 2016] To mock or not to mock, that is the question
anabalica
0
300
[DjangoCon Europe 2016] To mock or not to mock, that is the question
anabalica
0
380
[PyLadies London 2015] How to write a good commit message
anabalica
0
390
[EuroPython 2015] Demystifying Mixins with Django
anabalica
0
330
[DjangoCon Europe 2015] Demystifying Mixins with Django
anabalica
0
300
Other Decks in Programming
See All in Programming
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
110
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
190
Outline View in SwiftUI
1024jp
1
320
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
140
Contemporary Test Cases
maaretp
0
130
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
243
12k
BBQ
matthewcrist
85
9.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Thoughts on Productivity
jonyablonski
67
4.3k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Writing Fast Ruby
sferik
627
61k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
How STYLIGHT went responsive
nonsquared
95
5.2k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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