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
550
[DjangoCon US] Testing in Django
anabalica
1
1.2k
HTTP: History & Performance
anabalica
1
560
[DUTH] Testing in Django
anabalica
4
9.6k
[PyCon US 2016] To mock or not to mock, that is the question
anabalica
0
330
[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
Going Structural with Named Tuples
bishabosha
0
200
php-fpm がリクエスト処理する仕組みを追う / Tracing-How-php-fpm-Handles-Requests
shin1x1
5
2.9k
Making TCPSocket.new "Happy"!
coe401_
1
130
Kubernetesで実現できるPlatform Engineering の現在地
nwiizo
3
1.9k
SwiftUI API Design Lessons
niw
1
260
S3静的ホスティング+Next.js静的エクスポート で格安webアプリ構築
iharuoru
0
220
Chrome Extension Techniques from Hell
moznion
1
160
Preact、HooksとSignalsの両立 / Preact: Harmonizing Hooks and Signals
ssssota
1
1.4k
remix + cloudflare workers (DO) docker上でいい感じに開発する
yoshidatomoaki
0
130
メモリウォールを超えて:キャッシュメモリ技術の進歩
kawayu
0
1.9k
タイムゾーンの奥地は思ったよりも闇深いかもしれない
suguruooki
1
580
Agentic Applications with Symfony
el_stoffel
2
270
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Raft: Consensus for Rubyists
vanstee
137
6.9k
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
Documentation Writing (for coders)
carmenintech
69
4.7k
Git: the NoSQL Database
bkeepers
PRO
430
65k
GraphQLの誤解/rethinking-graphql
sonatard
71
10k
Producing Creativity
orderedlist
PRO
344
40k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
23
2.6k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
52
2.4k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
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