DjangoCon US 2016 - I Didn't Know Querysets Could do That by Charlie Guo
I Didn't Know Querysets Could do That by Charlie Guo
QuerySets and object Managers are a core part of Django, and can be extremely powerful. But I didn't always know about some of their more advanced capabilities.
BASIC METHODS
You have likely used filter(), exclude(), and order_by(). You've even probably used an aggregation method like Sum() or Count(). Less common, however, are query(), only()/defer(), and select_related().
F EXPRESSIONS / Q OBJECTS
For some more complex queries, those basic functions and filters won't cut it. How do you construct a query that needs to check for field A or field B? What do you do if you need to multiply two fields together and then sum them? Look no further than F() and Q().
RAW SQL / THE EXTRA() METHOD
As a last resort, it's entirely possible to use raw SQL queries to get the database results that you need. The sky's the limit, but there are definitely downsides to this approach; pitfalls include SQL injections and database backend portability issues.
MANAGERS
A talk on QuerySets would be incomplete without mentioning Managers, and how to leverage Manager customization to make your life easier. Writing methods on existing Managers, and creating custom ones can go a long way towards being DRY and reducing the potential for errors.
This talk was presented at: https://2016.djangocon.us/schedule/presentation/43/
LINKS:
Follow DjangCon US 👇
https://twitter.com/djangocon
Follow DEFNA 👇
https://twitter.com/defnado
https://www.defna.org/
Видео DjangoCon US 2016 - I Didn't Know Querysets Could do That by Charlie Guo канала DjangoCon US
QuerySets and object Managers are a core part of Django, and can be extremely powerful. But I didn't always know about some of their more advanced capabilities.
BASIC METHODS
You have likely used filter(), exclude(), and order_by(). You've even probably used an aggregation method like Sum() or Count(). Less common, however, are query(), only()/defer(), and select_related().
F EXPRESSIONS / Q OBJECTS
For some more complex queries, those basic functions and filters won't cut it. How do you construct a query that needs to check for field A or field B? What do you do if you need to multiply two fields together and then sum them? Look no further than F() and Q().
RAW SQL / THE EXTRA() METHOD
As a last resort, it's entirely possible to use raw SQL queries to get the database results that you need. The sky's the limit, but there are definitely downsides to this approach; pitfalls include SQL injections and database backend portability issues.
MANAGERS
A talk on QuerySets would be incomplete without mentioning Managers, and how to leverage Manager customization to make your life easier. Writing methods on existing Managers, and creating custom ones can go a long way towards being DRY and reducing the potential for errors.
This talk was presented at: https://2016.djangocon.us/schedule/presentation/43/
LINKS:
Follow DjangCon US 👇
https://twitter.com/djangocon
Follow DEFNA 👇
https://twitter.com/defnado
https://www.defna.org/
Видео DjangoCon US 2016 - I Didn't Know Querysets Could do That by Charlie Guo канала DjangoCon US
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
DjangoCon US 2016 - Mighty Model Managers by Shawn InmanSebastian Witowski - Wait, IPython can do that?!Object Storage with Django (Digital Ocean Spaces S3)Database Relationships | One To Many & Many to Many | Django (3.0) Crash Course Tutorials (pt 6)DjangoCon 2019 - Prefetching for Fun and Profit by Mike HansenCaching Techniques - Web DevelopmentDjangoCon US 2016 - Django for IOT: From Hackathon to Production by Anna SchneiderTry DJANGO Tutorial - 26 - Form WidgetsHow Model Queries Work in DjangoHow I Sold My Python/Django Website for $41,000DjangoCon 2019 - Building effective Django queries with expressions by Vanessa BarreirosDjangoCon US 2018 - Elasticsearch: Accelerating the Django Admin by Kate KligmanSimple Hacks to Make Your Django Website Faster - PyCon India 2015Cookies in Browsers and DjangoTry Django 1.9 - 36 of 38 - Model Managers & Handling DraftsDjangoCon 2019 - Pushing the ORM to its limitsDjangoCon 2019 - Eita! Why Internationalization and Localization matter by Nicolle CysneirosDjango Design Patterns - URLs Best Practises (Part 1)DjangoCon 2019 - Generic View? What is that and why would I use it? by Felipe LeeDjangoCon 2019- The promised Django Land; the tale of one team’s epic journey... by Nicole Zuckerman