Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Django and PostgreSQL, a happy relationship
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Iacopo Spalletti
October 23, 2015
Programming
57
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Django and PostgreSQL, a happy relationship
Given at PgDay Italy 2015 23 October 2015
Iacopo Spalletti
October 23, 2015
More Decks by Iacopo Spalletti
See All by Iacopo Spalletti
FastHTML: HTML applications, the Python way
yakky
0
92
Django dalle trincee: pattern e pratiche dopo 15 anni di esperienza su Django
yakky
0
130
Writing Async Microservices in Python
yakky
0
1k
1 API - 3 Framework - 30 minutes
yakky
0
120
Building real time applications with Django and Channels 2 @ DjangoCon Europe
yakky
1
940
Building real time applications with Django and Channels 2 @ PyCon Italia
yakky
0
760
Building real time applications with Django
yakky
0
920
django knocker
yakky
0
94
django CMS application - A comprehensive approach
yakky
0
76
Other Decks in Programming
See All in Programming
phperだってパンチカードでコーディングしたい
o0h
PRO
0
330
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
220
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
270
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
2
550
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
R8 の設定見直しでアプリサイズ削減
andpad
0
220
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
430
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Designing Powerful Visuals for Engaging Learning
tmiket
1
610
Chasing Engaging Ingredients in Design
codingconduct
0
360
Embracing the Ebb and Flow
colly
88
5.2k
Why Our Code Smells
bkeepers
PRO
340
58k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
750
Making Projects Easy
brettharned
120
6.8k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
600
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
The SEO Collaboration Effect
kristinabergwall1
1
590
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Transcript
PGDAY 2015 DJANGO AND POSTGRESQL, A HAPPY RELATIONSHIP by Iacopo
Spalletti @yakkys
WHO AM I? Founder and Lead developer @NephilaIt django CMS
core developer django CMS installer author
WHAT'S DJANGO? A web framework written in Python Based on
an DBMS-agnostic ORM
DJANGO ORM But sometimes abstraction is not enough
POSTGRESQL EXTENSIONS PostGIS Support django-hstore django.contrib.postgres
DJANGO-HSTORE External application to support hstore datatype Supports Django 1.6-1.8+
Integrated editor
DJANGO-HSTORE Easy to use class PrinterData(models.Model): printer = models.ForeignKey(Printer) data
= hstore.DictionaryField() ... objects = hstore.HStoreManager() That's all (plus run create extension hstore)
DJANGO-HSTORE Demo time
CONTRIB.POSTGRES Official module Available since 1.8 Supports many datatypes UUID
HStore Array Rangefields
CONTRIB.POSTGRES UUID class Example(models.Model): id = models.UUIDField(default=uuid.uuid4, primary_key=True)
CONTRIB.POSTGRES ARRAYFIELD class Post(models.Model): name = models.CharField(max_length=200) tags = ArrayField(models.CharField(max_length=200))
Supports query functions: contains (@>), contained_by (<@), overlap (&&), len, indexing, slicing
CONTRIB.POSTGRES ARRAYFIELD # SQL operator: @> Post.objects.filter(tags__contains=['thoughts']) # SQL operator:
<@ Post.objects.filter(tags__contained_by=['thoughts', 'django']) # SQL operator: && Post.objects.filter(tags__overlap=['thoughts']) # len Post.objects.filter(tags__len=1) # indexing Post.objects.filter(tags__1__iexact='django') # slicing Post.objects.filter(tags__1_2='thoughts')
CONTRIB.POSTGRES HSTORE class Post(models.Model): name = models.CharField(max_length=200) data = HStoreField()
Support query functions: filter, chaining, contains, contained_by, has_key, has_any_key, has_keys
CONTRIB.POSTGRES HSTORE # filter Post.objects.filter(data__category='main') # chaining Post.objects.filter(data__category__contains='h') # SQL
operator: @> Post.objects.filter(data__contains={'category': 'home'}) # SQL operator: <@ Post.objects.filter(data__contained_by={'category': 'home', 'author' # SQL operator: ? Post.objects.filter(data__has_key='category') # SQL operator: ?| Post.objects.filter(data__has_any_keys='category') # SQL operator: ?& Post.objects.filter(data__has_keys=['category', 'author'])
CONTRIB.POSTGRES RANGE FIELDS python_2_unicode_compatible class Post(models.Model): name = models.CharField(max_length=200) ...
skill_range = IntegerRangeField() Supports a lot of query functions: contains, contained_by, overlap, fully_lt, fully_gt, not_lt, not_gt, adjacent_to, startswith, endswith, isempty Definition of custom range types
CONTRIB.POSTGRES RANGE FIELDS # SQL operator: @> Post.objects.filter(skill_range__contains=NumericRange(3, 5)) #
SQL operator: <@ Post.objects.filter(skill_range__contained_by=NumericRange(2, 3)) # SQL operator: && Post.objects.filter(skill_range__overlap=NumericRange(2, 3)) # fully_lt Post.objects.filter(skill_range__fully_lt=NumericRange(3, 6)) # fully_gt Post.objects.filter(skill_range__fully_gt=NumericRange(2, 3))
DJANGO AND POSTGRESQL Support is evolving More goodies in 1.9
GRAZIE!