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
160
Other Decks in Programming
See All in Programming
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
240
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
2
100
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
3
1.8k
メールのエイリアス機能を履き違えない
isshinfunada
0
250
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
580
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
5
510
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
250
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
500
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
160
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
170
Android CLI
fornewid
0
230
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
240
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
1.1k
Raft: Consensus for Rubyists
vanstee
141
7.6k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
470
Facilitating Awesome Meetings
lara
57
7.1k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
340
Believing is Seeing
oripsolob
1
200
Game over? The fight for quality and originality in the time of robots
wayneb77
1
250
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
500
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
620
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
We Have a Design System, Now What?
morganepeng
55
8.3k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
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 ?