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
Django and PostgreSQL, a happy relationship
Search
Iacopo Spalletti
October 23, 2015
Programming
56
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
81
Django dalle trincee: pattern e pratiche dopo 15 anni di esperienza su Django
yakky
0
130
Writing Async Microservices in Python
yakky
0
980
1 API - 3 Framework - 30 minutes
yakky
0
120
Building real time applications with Django and Channels 2 @ DjangoCon Europe
yakky
1
930
Building real time applications with Django and Channels 2 @ PyCon Italia
yakky
0
750
Building real time applications with Django
yakky
0
910
django knocker
yakky
0
90
django CMS application - A comprehensive approach
yakky
0
74
Other Decks in Programming
See All in Programming
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
170
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
140
AIエージェント時代のコードレビューを設計する
nogu66
5
2.5k
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
2
300
typoなんかねぇよ
raspython3
0
660
不幸な GC
chencmd
0
870
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
4
2.8k
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
330
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
350
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
660
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
280
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
230
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
800
The Mindset for Success: Future Career Progression
greggifford
PRO
0
490
Done Done
chrislema
186
16k
Code Reviewing Like a Champion
maltzj
528
40k
How to build a perfect <img>
jonoalderson
1
5.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
330
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Technical Leadership for Architectural Decision Making
baasie
3
550
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
310
Chasing Engaging Ingredients in Design
codingconduct
0
300
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!