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
250
mauvaises bonnes idées pour REST
xordoquy
1
340
Authentication and Permissions with Django REST framework
xordoquy
0
170
Buildbot 0.9
xordoquy
0
96
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
Spring gRPC について / About Spring gRPC
mackey0225
0
220
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
150
Honoのおもしろいミドルウェアをみてみよう
yusukebe
1
210
第3回 Snowflake 中部ユーザ会- dbt × Snowflake ハンズオン
hoto17296
4
370
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
190
color-scheme: light dark; を完全に理解する
uhyo
3
200
Unity Android XR入門
sakutama_11
0
150
Software Architecture
hschwentner
6
2.1k
Writing documentation can be fun with plugin system
okuramasafumi
0
120
バックエンドのためのアプリ内課金入門 (サブスク編)
qnighy
8
1.8k
Formの複雑さに立ち向かう
bmthd
1
830
もう僕は OpenAPI を書きたくない
sgash708
4
1.4k
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
223
9.3k
GraphQLとの向き合い方2022年版
quramy
44
13k
Become a Pro
speakerdeck
PRO
26
5.1k
A Tale of Four Properties
chriscoyier
158
23k
Being A Developer After 40
akosma
89
590k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
240
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
How to train your dragon (web standard)
notwaldorf
91
5.8k
Optimizing for Happiness
mojombo
376
70k
How to Ace a Technical Interview
jacobian
276
23k
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 ?