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
Ordoquy Xavier - Linovia
September 28, 2013
Programming
0
150
Swappable Models - DjangoCong 2013
Ordoquy Xavier - Linovia
September 28, 2013
Tweet
Share
More Decks by Ordoquy Xavier - Linovia
See All by Ordoquy Xavier - Linovia
SQLAlchemy - un ami qui vous veut du bien
xordoquy
0
7
pycon.fr 2018 - Django REST framework workshop
xordoquy
0
340
mauvaises bonnes idées pour REST
xordoquy
1
380
Authentication and Permissions with Django REST framework
xordoquy
0
190
Buildbot 0.9
xordoquy
0
100
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
120
Django REST framework - DjangoConG 2015
xordoquy
3
140
Other Decks in Programming
See All in Programming
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
380
AI時代の認知負荷との向き合い方
optfit
0
160
Package Management Learnings from Homebrew
mikemcquaid
0
230
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
120
AtCoder Conference 2025
shindannin
0
1.1k
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
Claude Codeと2つの巻き戻し戦略 / Two Rewind Strategies with Claude Code
fruitriin
0
140
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
760
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
470
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
250
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.5k
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
590
It's Worth the Effort
3n
188
29k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
So, you think you're a good person
axbom
PRO
2
1.9k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
180
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.2k
Ethics towards AI in product and experience design
skipperchong
2
200
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
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 ?