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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
25
pycon.fr 2018 - Django REST framework workshop
xordoquy
0
360
mauvaises bonnes idées pour REST
xordoquy
1
410
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
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.7k
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
380
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
150
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.5k
メールのエイリアス機能を履き違えない
isshinfunada
0
240
Go 1.27 における memory allocation の高速化
andpad
0
180
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
250
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
400
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
560
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.7k
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
280
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
510
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
540
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
530
エンジニアに許された特別な時間の終わり
watany
108
250k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
430
ラッコキーワード サービス紹介資料
rakko
1
4.4M
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
860
Game over? The fight for quality and originality in the time of robots
wayneb77
1
240
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
290
My Coaching Mixtape
mlcsv
0
230
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 ?