Reference GeoDjango Tutorial
When doing spatial queries, GeoDjango automatically transforms geometries if they’re in a different coordinate system.
1413 sections across all versions Narrow to Django 6.0 (current) →
Reference GeoDjango Tutorial
When doing spatial queries, GeoDjango automatically transforms geometries if they’re in a different coordinate system.
Reference Databases
Another option is to wrap each QuerySet using server-side cursors in an atomic() block, because it disables autocommit for the duration of the transaction. This way, the server-side cursor will only live for the duration of the transaction.
Reference Database Functions
classExtract(expression,lookup_name=None,tzinfo=None,**extra)[source] Extracts a component of a date as a number. Takes an expression representing a DateField, DateTimeField, TimeField, or DurationField and a lookup_name, and returns the part of the date referenced by lookup_name as an IntegerField.
Reference Query Expressions
As well as being used in operations on single instances as above, F() can be used with update() to perform bulk updates on a QuerySet.
Reference Model Meta options Available Meta options
Options.ordering : The default ordering for the object, for use when obtaining lists of objects: NOTE: In GROUP BY queries (for example, > those using values() and annotate()), the > default ordering is not applied.
Topic guide
Article.objects.filter(reporter__first_name="John") <QuerySet [<Article: John's second story>, <Article: This is a test>]> Query twice over the related field.
Topic guide Models
NOTE: Note that the delete() method for an object is not > necessarily called when deleting objects in bulk using a > QuerySet or as a result of a cascading delete > (see on_delete).
Topic guide Making queries
To represent database-table data in Python objects, Django uses an intuitive system: A model class represents a database table, and an instance of that class represents a particular record in the database table.
Topic guide Making queries
Subsequent accesses to the foreign key on the same object instance are cached. Example: Note that the select_related() QuerySet method recursively prepopulates the cache of all one-to-many relationships ahead of time. Example:
Topic guide Making queries
You would expect it to return the entry e. However, the filter condition, which traverses the many-to-many relationship between Entry and Author, yields an empty QuerySet.
Topic guide Pagination
… you methods for accessing the items for each page: NOTE: Note that you can give Paginator a list/tuple, a Django QuerySet, > or any other object with a count() or __len__() method. When > determining the number of objects contained …
Topic guide Testing tools
SimpleTestCase.assertJSONNotEqual(raw,expected_data,msg=None)[source] : Asserts that the JSON fragments raw and expected_data are not equal. See assertJSONEqual() for further details. TransactionTestCase.assertQuerySetEqual(qs,values,transform=None,ordered=True,msg=None)[source] : Asserts that a queryset qs matches a particular iterable of values values.
queryset : An object representing some set of rows to be fetched from the database. slug : A short label for something, containing only letters, numbers, underscores or hyphens. They’re generally used in URLs.
How-to How to create custom model fields Writing a field subclassUseful methods
The methods are also called when constructing a WHERE clause that includes the model field – that is, when you retrieve data using QuerySet methods like get(), filter(), and exclude() and have the model field as an argument.
Internals Django Deprecation Timeline
See the Django 1.5 release notes for more details on these changes. The module django.utils.simplejson will be removed. The standard library provides json which should be used instead. The function django.utils.itercompat.product will be removed.
Internals The Django source code repository Tags
queryset-refactor: A refactoring of the internals of Django’s object-relational mapper. This became part of Django as of the 1.0 release. unicode: A refactoring of Django’s internals to consistently use Unicode-based strings in most places within Django and Django applications.
Internals Django’s security policies Reporting security issuesReporting guidelines
Reports based on a failure to sanitize user input are not valid security vulnerabilities. It is the developer’s responsibility to properly handle user input. This principle is explained in our security documentation.
Reference Applications Initialization process
For example, a common mistake is making a database query to populate form field choices: In the example above, the query from Country.objects.all() is executed during module import, because the QuerySet is iterated over.
Reference Class-based generic views - flattened index Date-based views
… accessor): allow_empty [get_allow_empty()] allow_future [get_allow_future()] content_type context_object_name [get_context_object_name()] date_field [get_date_field()] extra_context http_method_names model ordering [get_ordering()] paginate_by [get_paginate_by()] paginate_orphans [get_paginate_orphans()] paginator_class queryset [get_queryset()] response_class [render_to_response()] template_engine template_name [get_template_names()] template_name_suffix Methods as_view() dispatch() get() get_context_data() get_date_list() get_dated_items() get_dated_queryset() get_paginator() head() http_method_not_allowed() paginate_queryset() …
Reference Class-based generic views - flattened index Date-based views
… (with optional accessor): allow_future [get_allow_future()] content_type context_object_name [get_context_object_name()] date_field [get_date_field()] day [get_day()] day_format [get_day_format()] extra_context http_method_names model month [get_month()] month_format [get_month_format()] pk_url_kwarg query_pk_and_slug queryset [get_queryset()] response_class [render_to_response()] slug_field [get_slug_field()] slug_url_kwarg template_engine template_name [get_template_names()] template_name_field template_name_suffix year [get_year()] year_format [get_year_format()] Methods