djangodocs.org

477 sections across all versions Narrow to Django 6.0 (current) →

A transformer example

How-to How to write custom lookups

The custom lookup above is great, but in some cases you may want to be able to chain lookups together. For example, let’s suppose we are building an application where we want to make use of the abs() operator.

dev

How-to How to write custom lookups

The AbsoluteValue example we discussed previously is a transformation which applies to the left-hand side of the lookup. There may be some cases where you want the transformation to be applied to both the left-hand side and the right-hand side.

dev

1.8

Internals Django Deprecation Timeline

See the Django 1.6 release notes for more details on these changes. django.contrib.comments will be removed.

dev

Database setup

Tutorial Writing your first Django app, part 2

Now, open up mysite/settings.py. It’s a normal Python module with module-level variables representing Django settings. By default, the DATABASES configuration uses SQLite. If you’re new to databases, or you’re just interested in trying Django, this is the easiest choice.

dev

Write a minimal form

Tutorial Writing your first Django app, part 4

Let’s update our poll detail template (“polls/detail.html”) from the last tutorial, so that the template contains an HTML <form> element: polls/templates/polls/detail.html A quick rundown: The above template displays a radio button for each question choice.

dev

Configurable attributes

Reference Applications

AppConfig.name : Full Python path to the application, e.g. 'django.contrib.admin'. AppConfig.label : Short name for the application, e.g. 'admin' AppConfig.verbose_name : Human-readable name for the application, e.g. “Administration”. AppConfig.path : Filesystem path to the application directory, e.g. '/usr/lib/pythonX.Y/dist-packages/django/contrib/admin'.

dev

dbshell

Reference django-admin and manage.py Available commands

django-admin dbshell Runs the command-line client for the database engine specified in your ENGINE setting, with the connection parameters specified in your USER, PASSWORD, etc., settings. For PostgreSQL, this runs the psql command-line client.

shell

Reference django-admin and manage.py Available commands

django-admin shell Starts the Python interactive interpreter. All models from installed apps are automatically imported into the shell environment. Models from apps listed earlier in INSTALLED_APPS take precedence.

Reference QuerySet API reference

Internally, a QuerySet can be constructed, filtered, sliced, and generally passed around without actually hitting the database. No database activity actually occurs until you do something to evaluate the queryset. You can evaluate a QuerySet in the following ways: Iteration.

dev

explain()

Reference QuerySet API reference

explain(format=None,**options) aexplain(format=None,**options) Asynchronous version: aexplain() Returns a string of the QuerySet’s execution plan, which details how the database would execute the query, including any indexes or joins that would be used.

dev

AnyValue

Reference QuerySet API reference

classAnyValue(expression,output_field=None,filter=None,default=None,**extra)[source] : Returns an arbitrary value from the non-null input values.

dev

Topic guide Django’s cache framework

If you’re after even more control, you can also cache template fragments using the cache template tag. To give your template access to this tag, put {% load cache %} near the top of your template.

dev

Topic guide Aggregation

Fields that are mentioned in the order_by() part of a queryset are used when selecting the output data, even if they are not otherwise specified in the values() call.

dev

Topic guide Aggregation

When using the values() clause to group query results for annotations in MySQL with the ONLY_FULL_GROUP_BY SQL mode enabled, you may need to apply AnyValue if the annotation includes a mix of aggregate and non-aggregate expressions.

dev

Field name restrictions

Topic guide Models

Django places some restrictions on model field names: A field name cannot be a Python reserved word, because that would result in a Python syntax error.

dev

Topic guide Making queries

Keyword argument queries – in filter(), etc. – are “AND”ed together. If you need to execute more complex queries (for example, queries with OR statements), you can use Q() objects.

dev

Topic guide Translation

Contrarily to the translate tag, the blocktranslate tag allows you to mark complex sentences consisting of literals and variable content for translation by making use of placeholders: To translate a template expression – say, accessing object attributes or using template …

dev