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
xordoquy
September 28, 2013
Programming
0
150
Swappable Models - DjangoCong 2013
xordoquy
September 28, 2013
Tweet
Share
More Decks by xordoquy
See All by xordoquy
pycon.fr 2018 - Django REST framework workshop
xordoquy
0
290
mauvaises bonnes idées pour REST
xordoquy
1
350
Authentication and Permissions with Django REST framework
xordoquy
0
180
Buildbot 0.9
xordoquy
0
97
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
110
Django REST framework - DjangoConG 2015
xordoquy
3
140
Django REST framework workshop - DjangoCong 2015
xordoquy
1
110
Other Decks in Programming
See All in Programming
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
3
1.9k
iOSアプリ開発もLLMで自動運転する
hiragram
6
2.3k
実践ArchUnit ~実例による検証パターンの紹介~
ogiwarat
2
240
Perlで痩せる
yuukis
1
680
TypeScript を活かしてデザインシステム MCP を作る / #tskaigi_after_night
izumin5210
5
520
〜可視化からアクセス制御まで〜 BigQuery×Looker Studioで コスト管理とデータソース認証制御する方法
cuebic9bic
3
320
単体テストの始め方/作り方
toms74209200
0
420
Development of an App for Intuitive AI Learning - Blockly Summit 2025
teba_eleven
0
110
GoのGenericsによるslice操作との付き合い方
syumai
1
340
Your Architecture as a Crime Scene:Forensic Analysis
manfredsteyer
PRO
0
100
ドメインモデリングにおける抽象の役割、tagless-finalによるDSL構築、そして型安全な最適化
knih
10
1.7k
イベントストーミングから始めるドメイン駆動設計
jgeem
4
800
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Building Adaptive Systems
keathley
43
2.6k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
A Tale of Four Properties
chriscoyier
159
23k
Typedesign – Prime Four
hannesfritz
42
2.7k
Why Our Code Smells
bkeepers
PRO
337
57k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
The Invisible Side of Design
smashingmag
299
50k
Agile that works and the tools we love
rasmusluckow
329
21k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
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 ?