Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PostgreSQL & Django - a tasty mix

PostgreSQL & Django - a tasty mix

My talk at PyWaw #26.
http://www.pywaw.org/08-07-2013

Zbigniew Siciarz

July 08, 2013
Tweet

More Decks by Zbigniew Siciarz

Other Decks in Technology

Transcript

  1. DjangoCon-inspired • Advanced PostgreSQL in Django by Christophe Pettus http://www.youtube.com/watch?v=C3bZbA4jaAg

    • Getting past the Django ORM limitations with Postgres by Craig Kerstiens http://www.youtube.com/watch?v=sXmFK_qsvlo
  2. Case study • pretty slides are pretty, but show me

    the code • practical example? • yet another online photo gallery… • …built with Django… • …using PostgreSQL goodies!
  3. NoSQL in my SQL?! • HStore is a key value

    store within Postgres. You can use it similar to how you would use a dictionary within another language […] – Craig Kerstiens, Postgres Guide http://postgresguide.com/sexy/hstore.html • CREATE EXTENSION hstore;
  4. django-hstore • pip install django-hstore • exif = hstore.DictionaryField(db_index=True) •

    photo.exif = {‘FocalLength’: ‘11’} • South sometimes gets confused • custom database backend • who maintains the code?
  5. djorm-ext-hstore • fork of django-hstore • actively maintained and improved

    • plays nice with South • no need for custom database backend • Yay!
  6. [] • multiple values of the same type in one

    column • built-in; no extension needed • variable length arrays • maps well to a Python list
  7. djorm-ext-pgarray • same maintainer as djorm-ext-hstore and other ORM extensions

    • provides model field and form field • pip install djorm-ext-pgarray • or… • https://github.com/ntucker/djorm-ext-pgarray (better tag string parsing in ArrayFormField)
  8. @> • @> means „contains” • zs=> select array[1,2,3] @>

    array[2,1]; ?column? ---------- t (1 row) • use djorm-ext-expressions for Pythonic syntax
  9. Putting it all together • django-pgallery https://github.com/zsiciarz/django-pgallery • proof-of-concept code

    • TODO: tests, docs, better templates… • pull requests are welcome :-)