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 ...
Get Django: Web Development with Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.