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
48
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
69
Django dalle trincee: pattern e pratiche dopo 15 anni di esperienza su Django
yakky
0
120
Writing Async Microservices in Python
yakky
0
970
1 API - 3 Framework - 30 minutes
yakky
0
110
Building real time applications with Django and Channels 2 @ DjangoCon Europe
yakky
1
920
Building real time applications with Django and Channels 2 @ PyCon Italia
yakky
0
740
Building real time applications with Django
yakky
0
890
django knocker
yakky
0
85
django CMS application - A comprehensive approach
yakky
0
70
Other Decks in Programming
See All in Programming
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.7k
メールのエイリアス機能を履き違えない
isshinfunada
0
220
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
450
AIが無かった頃の素敵な出会いの話
codmoninc
1
390
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
370
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.9k
源内ハンズオン概要編
hideg
0
120
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
370
霧の中の代数的エフェクト
funnyycat
1
480
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
220
Foundation Models frameworkで画像分析
ryodeveloper
1
590
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
340
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
360
Music & Morning Musume
bryan
47
7.3k
Marketing to machines
jonoalderson
1
5.6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
630
Into the Great Unknown - MozCon
thekraken
41
2.7k
Producing Creativity
orderedlist
PRO
348
40k
GraphQLとの向き合い方2022年版
quramy
50
15k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
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!