Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Django and PostgreSQL, a happy relationship
Search
Iacopo Spalletti
October 23, 2015
Programming
0
38
Django and PostgreSQL, a happy relationship
Given at PgDay Italy 2015 23 October 2015
Iacopo Spalletti
October 23, 2015
Tweet
Share
More Decks by Iacopo Spalletti
See All by Iacopo Spalletti
Django dalle trincee: pattern e pratiche dopo 15 anni di esperienza su Django
yakky
0
73
Writing Async Microservices in Python
yakky
0
830
1 API - 3 Framework - 30 minutes
yakky
0
100
Building real time applications with Django and Channels 2 @ DjangoCon Europe
yakky
1
800
Building real time applications with Django and Channels 2 @ PyCon Italia
yakky
0
640
Building real time applications with Django
yakky
0
790
django knocker
yakky
0
60
django CMS application - A comprehensive approach
yakky
0
54
django CMS + Channels + DRF = ♥
yakky
0
320
Other Decks in Programming
See All in Programming
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
130
マスタデータ問題、マイクロサービスでどう解くか
kts
0
130
AIコーディングエージェント(Manus)
kondai24
0
210
Python札幌 LT資料
t3tra
7
1k
안드로이드 9년차 개발자, 프론트엔드 주니어로 커리어 리셋하기
maryang
1
140
Claude Codeの「Compacting Conversation」を体感50%減! CLAUDE.md + 8 Skills で挑むコンテキスト管理術
kmurahama
1
640
Rubyで鍛える仕組み化プロヂュース力
muryoimpl
0
160
TerraformとStrands AgentsでAmazon Bedrock AgentCoreのSSO認証付きエージェントを量産しよう!
neruneruo
4
1.8k
re:Invent 2025 のイケてるサービスを紹介する
maroon1st
0
150
PC-6001でPSG曲を鳴らすまでを全部NetBSD上の Makefile に押し込んでみた / osc2025hiroshima
tsutsui
0
180
Giselleで作るAI QAアシスタント 〜 Pull Requestレビューに継続的QAを
codenote
0
300
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
120
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
0
78
エンジニアに許された特別な時間の終わり
watany
106
220k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
Odyssey Design
rkendrick25
PRO
0
440
Heart Work Chapter 1 - Part 1
lfama
PRO
3
35k
From π to Pie charts
rasagy
0
91
The browser strikes back
jonoalderson
0
120
ラッコキーワード サービス紹介資料
rakko
0
1.8M
A better future with KSS
kneath
240
18k
Writing Fast Ruby
sferik
630
62k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Building AI with AI
inesmontani
PRO
1
570
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!