PostgreSQL & Django - a tasty mix

PostgreSQL & Django - a tasty mix

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

97b6ddbf90c2a4428e668691e112d096?s=128

Zbigniew Siciarz

July 08, 2013
Tweet

Transcript

  1. PostgreSQL & Django A tasty mix PyWaw #26, 08.07.2013 Zbigniew

    Siciarz @zsiciarz http://siciarz.net
  2. 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
  3. Case study • pretty slides are pretty, but show me

    the code • practical example? • yet another online photo gallery… • …built with Django… • …using PostgreSQL goodies!
  4. HStore

  5. 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;
  6. This is Hastur, not HStore http://www.goominet.com/lovecraft/

  7. 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?
  8. Where do we go from here?

  9. djorm-ext-hstore • fork of django-hstore • actively maintained and improved

    • plays nice with South • no need for custom database backend • Yay!
  10. Storing EXIF data in HStore

  11. Storing EXIF data in HStore

  12. Storing EXIF data in HStore

  13. array

  14. [] • multiple values of the same type in one

    column • built-in; no extension needed • variable length arrays • maps well to a Python list
  15. 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)
  16. Tagging images

  17. @> • @> means „contains” • zs=> select array[1,2,3] @>

    array[2,1]; ?column? ---------- t (1 row) • use djorm-ext-expressions for Pythonic syntax
  18. Tags in forms

  19. Popular tags

  20. 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 :-)
  21. Questions?

  22. Thank you!