O'Reilly logo

Web Development with Django Cookbook - Second Edition by Aidas Bendoraitis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using database query expressions

Django Object-relational mapping (ORM) comes with special abstraction constructs that can be used to build complex database queries. They are called Query Expressions and they allow you to filter data, order it, annotate new columns, and aggregate relations. In this recipe, we will see how that can be used in practice. We will create an app that shows viral videos and counts how many times each video has been seen on mobile and desktop devices.

Getting ready

To start with, install django-mobile to your virtual environment. This module will be necessary to differentiate between desktop devices and mobile devices:

(myproject_env)$ pip install django-mobile

To configure it, you will need to modify several project settings ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required