postgres.aggregates.BoolOr

class BoolOr(expression, **extra) [source] Returns True if at least one input value is true, None if all values are null or if there are no values, otherwise False.

postgres.aggregates.BoolAnd

class BoolAnd(expression, **extra) [source] Returns True, if all input values are true, None if all values are null or if there are no values, otherwise False .

postgres.aggregates.BitOr

class BitOr(expression, **extra) [source] Returns an int of the bitwise OR of all non-null input values, or None if all values are null.

postgres.aggregates.BitAnd

class BitAnd(expression, **extra) [source] Returns an int of the bitwise AND of all non-null input values, or None if all values are null.

postgres.aggregates.ArrayAgg

class ArrayAgg(expression, **extra) [source] Returns a list of values, including nulls, concatenated into an array.

Porting to Python 3

Django 1.5 is the first version of Django to support Python 3. The same code runs both on Python 2 (≥ 2.6.5) and Python 3 (≥ 3.2), thanks to the six compatibility layer. This document is primarily targeted at authors of pluggable applications who want to support both Python 2 and 3. It also describes guidelines that apply to Django’s code. Philosophy This document assumes that you are familiar with the changes between Python 2 and Python 3. If you aren’t, read Python’s official porting guide fi

Performance and optimization

This document provides an overview of techniques and tools that can help get your Django code running more efficiently - faster, and using fewer system resources. Introduction Generally one’s first concern is to write code that works, whose logic functions as required to produce the expected output. Sometimes, however, this will not be enough to make the code work as efficiently as one would like. In this case, what’s needed is something - and in practice, often a collection of things - to impr

Outputting PDFs with Django

This document explains how to output PDF files dynamically using Django views. This is made possible by the excellent, open-source ReportLab Python PDF library. The advantage of generating PDF files dynamically is that you can create customized PDFs for different purposes – say, for different users or different pieces of content. For example, Django was used at kusports.com to generate customized, printer-friendly NCAA tournament brackets, as PDF files, for people participating in a March Madne

Outputting CSV with Django

This document explains how to output CSV (Comma Separated Values) dynamically using Django views. To do this, you can either use the Python CSV library or the Django template system. Using the Python CSV library Python comes with a CSV library, csv. The key to using it with Django is that the csv module’s CSV-creation capability acts on file-like objects, and Django’s HttpResponse objects are file-like objects. Here’s an example: import csv from django.http import HttpResponse def some_view(re

One-to-one relationships

To define a one-to-one relationship, use OneToOneField. In this example, a Place optionally can be a Restaurant: from django.db import models class Place(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=80) def __str__(self): # __unicode__ on Python 2 return "%s the place" % self.name class Restaurant(models.Model): place = models.OneToOneField( Place, on_delete=models.CASCADE, primary_key