Building effective Django queries with expressions - Vanessa Barreiros

Поделиться
HTML-код
  • Опубликовано: 11 окт 2024
  • This talk was presented at PyBay2019 - 4th annual Bay Area Regional Python conference. See pybay.com for more details about PyBay and click SHOW MORE for more information about this talk.
    Description
    In Django, we have a powerful tool called ORM to manipulate databases easily. For small queries, it can be quite simple, but what happens when you need to do tricks like nested queries or computed values? One of the answers is query expressions. In this talk, we'll learn how to power-up queries with them by walking through comparisons and examples with a dataset.
    Abstract
    It's known that ORMs are a powerful tool to manipulate databases with ease. In Django, there are a set of out-of-the-box abstractions to help perform queries and shape them through annotations, aggregations, order by, and so on, hence saving one's time. A common solution to filtering when models grow larger over time is creating redundant fields; a better solution is using Django built-in resources called query expressions.
    Query expressions are smart yet straightforward functions that one can use to compute values on query execution and do string manipulation, calculations, among others, thus removing the burden of having unnecessary extra columns in our database. Using query expressions effectively can help to generate performant queries, avoiding potential inconsistencies and separating concerns.
    This talk focuses on further optimizing Django queries by walking through code comparisons and examples with a dataset, diving into subjects such as custom database functions, conditional expressions, and filtering so to answer questions about the data.
    Original slides: t.ly/7P2mb
    About the speaker
    I'm a full stack developer at Vinta Software (www.vinta.com.br) and Django Girls organizer at my hometown, Recife. When not coding and working on personal projects, I'm usually cooking and watching Grey's Anatomy.
    Sponsor Acknowledgement
    This and other PyBay2019 videos are via the help of our media partner AlphaVoice (www.alphavoice...!
    #pybay #pybay2019 #python #python3 #gdb

Комментарии • 5

  • @khadimhusen
    @khadimhusen 4 года назад +3

    Really helpful for me.
    Thanks for this video.

  • @Luthier91
    @Luthier91 4 года назад

    Great watch. I will now have to go over all my @property (which felt like hacks, always had an itch when using them) and benchmark them against annotating the queryset as in 19:00, thanks for that neat piece of info!

  • @georgesmith3022
    @georgesmith3022 3 года назад +4

    the slides have been deleted :(

  • @acrossover
    @acrossover 3 года назад

    I am working with Python 3.7 + Django 2.2.17 + MongoDB (Djongo), but when I use Trunc (database function), ended up with error "raise NotImplementedError('subclasses of BaseDatabaseOperations may require a datetime_trunc_sql() method')" which makes me feel like django claims to support this DB function in official reference document (docs.djangoproject.com/en/2.2/ref/models/database-functions/#trunc), however it was not actually implemented in source code. Any thoughts ?

  • @MuhammadMoazzamhere
    @MuhammadMoazzamhere Год назад

    Please re upload these slides if possible.