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
Swappable Models - DjangoCong 2013
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ordoquy Xavier - Linovia
September 28, 2013
Programming
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swappable Models - DjangoCong 2013
Ordoquy Xavier - Linovia
September 28, 2013
More Decks by Ordoquy Xavier - Linovia
See All by Ordoquy Xavier - Linovia
SQLAlchemy - un ami qui vous veut du bien
xordoquy
0
19
pycon.fr 2018 - Django REST framework workshop
xordoquy
0
350
mauvaises bonnes idées pour REST
xordoquy
1
400
Authentication and Permissions with Django REST framework
xordoquy
0
200
Buildbot 0.9
xordoquy
0
110
Performances Django REST framework - DjangoCong 2016
xordoquy
0
130
Présentation de l'architecture REST - meetup Django Paris
xordoquy
0
110
Django REST framework workshop @Djangocon Europe 2015
xordoquy
0
130
Django REST framework - DjangoConG 2015
xordoquy
3
150
Other Decks in Programming
See All in Programming
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.1k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
280
net-httpのHTTP/2対応について
naruse
0
490
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
140
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
200
AIで効率化できた業務・日常
ochtum
0
140
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
790
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
260
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
AI 輔助遺留系統現代化的經驗分享
jame2408
1
380
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1.1k
New Earth Scene 8
popppiees
3
2.3k
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Typedesign – Prime Four
hannesfritz
42
3.1k
Google's AI Overviews - The New Search
badams
0
1k
The Pragmatic Product Professional
lauravandoore
37
7.3k
Become a Pro
speakerdeck
PRO
31
6k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
180
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
The browser strikes back
jonoalderson
0
1.3k
Design in an AI World
tapps
1
240
Transcript
Etendre son application avec les swappable models Xavier Ordoquy @linovia_net
Custom User dans son projet
Avant class UserProfile(models.Model): user = models.OneToOneField(User) accepted_eula = models.BooleanField() def
create_profile(sender, instance, created, **kwargs): if created: UserProfile.objects.create(user=instance) post_save.connect(create_profile, sender=User) models.py
Problèmes • createsuperuser / syncdb • email pour s’enregistrer •
complexe
Mais ça, c’était avant
Django 1.5 • python 3 •Custom User model • Support
des réponses streamées amélioré • Sauvegarde d’un sous ensemble des champs d’un modèle • ...
Après class CustomUser(User): accepted_eula = models.BooleanField() AUTH_USER_MODEL = 'myapp.CustomUser' models.py
settings.py
A savoir le UserProfile entre dans le processus d’obsolescence: suppression
pour Django 1.7
Contrat d’interface • USERNAME_FIELD • REQUIRED_FIELD • is_active • get_full_name
• get_short_name
Mise en place • définir le modèle • créer la
migration pour le modèle • adapter les formulaires • en profiter
ou pas ?
Librairies ? • django-registration • django-avatar (migrations) • django-socialauth •
django-social-auth (migrations)
Migrations ? • pas de support de migrations s’il y
a un ForeignKey vers le modèle d’utilisateur • $ ./manage.py syncdb --all • $ ./manage.py migrate --fake
Migrations ! migrations of models with FKs to swappable models
will work -- Andrew Godwin
Custom User dans librairie
Intégration ’’auth.User’’ User settings.AUTH_USER_MODEL get_user_model() migrations : ne rien changer
Plus loin Pourquoi ne pas l’utiliser sur d’autres modèles ?
1. Refactoring class User(BaseUser): ... ... class AbstractBaseUser(Model): class Meta:
abstract = True class BaseUser(AbstractBaseUser): class Meta: abstract = True class User(Model)
2. Touche finale class User(BaseUser): class Meta: if django.VERSION[0:2] >=
(1, 5): swappable = True def get_XXX_model(): 'Adaptez django.contrib.auth.get_user_model' ...
Photologue
Questions ?