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
330
[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
610
[DjangoCon US] Testing in Django
anabalica
1
1.3k
HTTP: History & Performance
anabalica
1
580
[DUTH] Testing in Django
anabalica
4
9.7k
[PyCon US 2016] To mock or not to mock, that is the question
anabalica
0
350
[DjangoCon Europe 2016] To mock or not to mock, that is the question
anabalica
0
480
[PyLadies London 2015] How to write a good commit message
anabalica
0
420
[EuroPython 2015] Demystifying Mixins with Django
anabalica
0
380
[DjangoCon Europe 2015] Demystifying Mixins with Django
anabalica
0
350
Other Decks in Programming
See All in Programming
Bakuraku E2E Scenario Test System Architecture #bakuraku_qa_study
teyamagu
PRO
0
670
CSC509 Lecture 09
javiergs
PRO
0
290
Designing Repeatable Edits: The Architecture of . in Vim
satorunooshie
0
260
AI時代に必須!状況言語化スキル / ai-context-verbalization
minodriven
3
370
自動テストを活かすためのテスト分析・テスト設計の進め方/JaSST25 Shikoku
goyoki
1
540
ノーコードからの脱出 -地獄のデスロード- / Escape from Base44
keisuke69
0
670
Vue 3.6 時代のリアクティビティ最前線 〜Vapor/alien-signals の実践とパフォーマンス最適化〜
hiranuma
2
430
Core MIDI を勉強して作曲用の電子ピアノ作ってみた!
hypebeans
0
100
Making Angular Apps Smarter with Generative AI: Local and Offline-capable
christianliebel
PRO
0
110
Honoを技術選定したAI要件定義プラットフォームAcsimでの意思決定
codenote
0
130
イベントストーミングのはじめかた / Getting Started with Event Storming
nrslib
1
180
ボトムアップの生成AI活用を推進する社内AIエージェント開発
aku11i
0
1.6k
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
246
12k
Facilitating Awesome Meetings
lara
57
6.6k
Bash Introduction
62gerente
615
210k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Pragmatic Product Professional
lauravandoore
36
7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
658
61k
Rails Girls Zürich Keynote
gr2m
95
14k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.2k
The Language of Interfaces
destraynor
162
25k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
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