Database access optimization

Django’s database layer provides various ways to help developers get the most out of their databases. This document gathers together links to the relevant documentation, and adds various tips, organized under a number of headings that outline the steps to take when attempting to optimize your database usage. Profile first As general programming practice, this goes without saying. Find out what queries you are doing and what they are costing you. You may also want to use an external project like

django.contrib.humanize

A set of Django template filters useful for adding a “human touch” to data. To activate these filters, add 'django.contrib.humanize' to your INSTALLED_APPS setting. Once you’ve done that, use {% load humanize %} in a template, and you’ll have access to the following filters. apnumber For numbers 1-9, returns the number spelled out. Otherwise, returns the number. This follows Associated Press style. Examples: 1 becomes one. 2 becomes two. 10 becomes 10. You can pass in either an integer or

utils.translation.to_locale()

to_locale(language) [source] Turns a language name (en-us) into a locale name (en_US).

http.HttpResponsePermanentRedirect

class HttpResponsePermanentRedirect [source] Like HttpResponseRedirect, but it returns a permanent redirect (HTTP status code 301) instead of a “found” redirect (status code 302).

postgres.forms.DateRangeField

class DateRangeField [source] Based on DateField and translates its input into DateRange. Default for DateRangeField.

gis.gdal.GDALBand.std

std New in Django 1.10. The standard deviation of all pixel values of the band (excluding the “no data” value).

urls.ResolverMatch.namespace

namespace The instance namespace for the URL pattern that matches the URL.

core.checks.CheckMessage

class CheckMessage(level, msg, hint=None, obj=None, id=None) [source] The warnings and errors raised by system checks must be instances of CheckMessage. An instance encapsulates a single reportable error or warning. It also provides context and hints applicable to the message, and a unique identifier that is used for filtering purposes. Constructor arguments are:

db.models.ForeignKey.swappable

ForeignKey.swappable Controls the migration framework’s reaction if this ForeignKey is pointing at a swappable model. If it is True - the default - then if the ForeignKey is pointing at a model which matches the current value of settings.AUTH_USER_MODEL (or another swappable model setting) the relationship will be stored in the migration using a reference to the setting, not to the model directly. You only want to override this to be False if you are sure your model should always point towar

gis.geoip.GeoIP.country()

GeoIP.country(query) Returns a dictionary with the country code and country for the given query.