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, you 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 by anonymous (versus logged-in) users.
Using database query expressions
Getting ready
To start, let's create the viral_videos app and add it under INSTALLED_APPS:
# settings.py or conf/base.py INSTALLED_APPS = ( # ... # local apps "utils", "viral_videos", )
Next, create...