Topic guide
How to install Django
If you plan to use Django’s database API functionality, you’ll need to make sure a database server is running. Django supports many different database servers and is officially supported with PostgreSQL, MariaDB, MySQL, Oracle and SQLite.
dev
Topic guide
Testing tools
You can tag your tests so you can easily run a particular subset.
dev
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.
4.2
5.0
5.1
5.2
6.0
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.
4.2
5.0
5.1
5.2
6.0
How-to
How to create custom model fields
When planning your Field subclass, first give some thought to which existing Field class your new field is most similar to. Can you subclass an existing Django field and save yourself some work?
4.2
5.0
5.1
5.2
6.0
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.
4.2
5.0
5.1
5.2
6.0
Reference
Applications
Application configuration
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'.
4.2
5.0
5.1
5.2
6.0
Reference
Conditional Expressions
Advanced queries
What if we want to find out how many clients there are for each account_type?
4.2
5.0
5.1
5.2
6.0
Reference
Model instance reference
Saving objects
You may have noticed Django database objects use the same save() method for creating and changing objects. Django abstracts the need to use INSERT or UPDATE SQL statements.
4.2
5.0
5.1
5.2
6.0
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.
4.2
5.0
5.1
5.2
6.0
Reference
QuerySet API reference
QuerySet APIMethods that return new QuerySets
values_list(*fields,flat=False,named=False) This is similar to values() except that instead of returning dictionaries, it returns tuples when iterated over.
5.2
6.0
Reference
QuerySet API reference
QuerySet APIMethods that do not return QuerySets
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.
4.2
5.0
5.1
5.2
6.0
Reference
QuerySet API reference
QuerySet APIAggregation functions
New in Django 6.0. classAnyValue(expression,output_field=None,filter=None,default=None,**extra)[source] : Returns an arbitrary value from the non-null input values.
6.0
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.
4.2
5.0
5.1
5.2
6.0
Topic guide
Aggregation
Aggregations and other QuerySet clausesvalues()
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.
4.2
5.0
5.1
5.2
6.0
Topic guide
Aggregation
Aggregations and other QuerySet clauses
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.
6.0
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.
4.2
5.0
5.1
5.2
6.0
Topic guide
Translation
Internationalization: in template code
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 …
4.2
5.0
5.1
5.2
6.0
Topic guide
How to install Django
If you plan to use Django’s database API functionality, you’ll need to make sure a database server is running. Django supports many different database servers and is officially supported with PostgreSQL, MariaDB, MySQL, Oracle and SQLite.
4.2
5.0
5.1
5.2
6.0
Topic guide
Testing tools
Test cases features
You can tag your tests so you can easily run a particular subset.
4.2
5.0
5.1
5.2
6.0