db.models.functions.datetime.Trunc

class Trunc(expression, kind, output_field=None, tzinfo=None, **extra) [source] Truncates a date up to a significant component. When you only care if something happened in a particular year, hour, or day, but not the exact second, then Trunc (and its subclasses) can be useful to filter or aggregate your data. For example, you can use Trunc to calculate the number of sales per day. Trunc takes a single expression, representing a DateField or DateTimeField, a kind representing a date part, and

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

core.checks.Error

class Error(msg, hint=None, obj=None, id=None) [source]

test.Client.options()

options(path, data='', content_type='application/octet-stream', follow=False, secure=False, **extra) [source] Makes an OPTIONS request on the provided path and returns a Response object. Useful for testing RESTful interfaces. When data is provided, it is used as the request body, and a Content-Type header is set to content_type. The follow, secure and extra arguments act the same as for Client.get().

core.validators.RegexValidator.message

message The error message used by ValidationError if validation fails. Defaults to "Enter a valid value".

core.files.storage.FileSystemStorage.location

location Absolute path to the directory that will hold the files. Defaults to the value of your MEDIA_ROOT setting.

http.HttpRequest.GET

HttpRequest.GET A dictionary-like object containing all given HTTP GET parameters. See the QueryDict documentation below.

Writing custom model fields

Introduction The model reference documentation explains how to use Django’s standard field classes – CharField, DateField, etc. For many purposes, those classes are all you’ll need. Sometimes, though, the Django version won’t meet your precise requirements, or you’ll want to use a field that is entirely different from those shipped with Django. Django’s built-in field types don’t cover every possible database column type – only the common types, such as VARCHAR and INTEGER. For more obscure col

urls.reverse()

reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None) [source] viewname can be a URL pattern name or the callable view object. For example, given the following url: from news import views url(r'^archive/$', views.archive, name='news-archive') you can use any of the following to reverse the URL: # using the named URL reverse('news-archive') # passing a callable object # (This is discouraged because you can't reverse namespaced views this way.) from news import views rev