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.
FAQ
FAQ: The admin
Using the same trick of extracting the user from the request, the get_queryset() and has_change_permission() can be used to control the visibility and editability of objects in the admin.
Index
… FAILED (TaskResultStatus attribute) - Feature (class in django.contrib.gis.gdal) - Feature release - Feed (class in django.contrib.gis.feeds) - fetch_mode() (in module django.db.models.query.QuerySet) - FETCH_ONE (in module django.db.models) - FETCH_PEERS (in module django.db.models) - FETCH_RAISE (in module django.db.models) - FetchFromCacheMiddleware (class in …
Index
… method) - page_kwarg (django.views.generic.list.MultipleObjectMixin attribute) - page_range (Paginator attribute) - PageNotAnInteger - paginate_by (django.views.generic.list.MultipleObjectMixin attribute) - paginate_orphans (django.views.generic.list.MultipleObjectMixin attribute) - paginate_queryset() (django.views.generic.list.MultipleObjectMixin method) - Paginator (class in django.core.paginator) - paginator (ModelAdmin attribute) - (Page attribute) - (Sitemap attribute) - paginator_class …
Index
… django.contrib.postgres.fields) - RangeWidget (class in django.contrib.postgres.forms) - Rank (class in django.db.models.functions) - RasterField (class in django.contrib.gis.db.models) - raw() (in module django.db.models.query.QuerySet) - (Manager method) - raw_id_fields (InlineModelAdmin attribute) - (ModelAdmin attribute) - RawSQL (class in django.db.models.expressions) - re_path() (in module …
Index
… - setting - SecurityMiddleware (class in django.middleware.security) - seekable() (HttpResponse method) - Select (class in django.forms) - select_for_update() (in module django.db.models.query.QuerySet) - select_on_save (Options attribute) - select_related() (in module django.db.models.query.QuerySet) - select_template() (Engine method) - (in module django.template.loader) - SelectDateWidget …
Index
… - unary_union (GEOSGeometry attribute) - Union (class in django.contrib.gis.db.models) - (class in django.contrib.gis.db.models.functions) - union() (GEOSGeometry method) - (in module django.db.models.query.QuerySet) - (OGRGeometry method) - unique (Field attribute) - unique_for_date (Field attribute) - unique_for_month (Field attribute) - unique_for_year (Field attribute) …
How-to
How to write custom lookups
For instance, if you want to filter a queryset based on the equality of the left and right-hand side insensitively to some SQL function. Let’s examine case-insensitive transformations here.
How-to
How to create custom model fields
If your custom Field class deals with data structures that are more complex than strings, dates, integers, or floats, then you may need to override from_db_value() and to_python().
Django documentation
… Model instances and relations: Instance methods | Accessing related objects | Content types and generic relations Queries: Making queries | QuerySet method reference | Lookup expressions | Query Expressions | Conditional Expressions | Custom lookups | Aggregation | Database Functions …
Internals
Django Deprecation Timeline
The Prefetch.get_current_queryset() method will be removed. The get_prefetch_queryset() method of related managers and descriptors will be removed. get_prefetcher() and prefetch_related_objects() will no longer fallback to get_prefetch_queryset(). The FORMS_URLFIELD_ASSUME_HTTPS transitional setting will be removed.
Internals
Django Deprecation Timeline
Support for pytz timezones will be removed. The is_dst argument will be removed from: QuerySet.datetimes() django.utils.timezone.make_aware() django.db.models.functions.Trunc() django.db.models.functions.TruncSecond() django.db.models.functions.TruncMinute() django.db.models.functions.TruncHour() django.db.models.functions.TruncDay() django.db.models.functions.TruncWeek() django.db.models.functions.TruncMonth() django.db.models.functions.TruncQuarter() django.db.models.functions.TruncYear() The django.contrib.gis.admin.GeoModelAdmin and OSMGeoAdmin classes will be removed. The undocumented BaseForm._html_output() method will be removed.
Internals
Django Deprecation Timeline
The default_app_config module variable will be removed. TransactionTestCase.assertQuerysetEqual() will no longer automatically call repr() on a queryset when compared to string values. django.core.cache.backends.memcached.MemcachedCache will be removed. Support for the pre-Django 3.2 format of messages used by django.contrib.messages.storage.cookie.CookieStorage will be removed.
Internals
Django Deprecation Timeline
Support for passing raw column aliases to QuerySet.order_by() will be removed. The model NullBooleanField will be removed. A stub field will remain for compatibility with historical migrations. django.conf.urls.url() will be removed. The model django.contrib.postgres.fields.JSONField will be removed.
Internals
Django Deprecation Timeline
The field_name keyword argument of QuerySet.earliest() and latest() will be removed. See the Django 2.1 release notes for more details on these changes. django.contrib.gis.db.models.functions.ForceRHR will be removed. django.utils.http.cookie_date() will be removed.
Internals
Django Deprecation Timeline
Remove the backward compatible shims introduced to rename get_query_set and similar queryset methods. This affects the following classes: BaseModelAdmin, ChangeList, BaseCommentNode, GenericForeignKey, Manager, SingleRelatedObjectDescriptor and ReverseSingleRelatedObjectDescriptor. Remove the backward compatible shims introduced to rename the attributes ChangeList.root_query_set and ChangeList.query_set.
Tutorial
Writing your first Django app, part 4
This is provided using either the model attribute (in this example, model = Question for DetailView and ResultsView) or by defining the get_queryset() method (as shown in IndexView).
Tutorial
Writing your first Django app, part 5
Let’s fix that. In Tutorial 4 we introduced a class-based view, based on ListView: polls/views.py We need to amend the get_queryset() method and change it so that it also checks the date by comparing it with timezone.now().
Tutorial
Writing your first Django app, part 5
What we have works well; however, even though future questions don’t appear in the index, users can still reach them if they know or guess the right URL.
Design philosophies
This is also why the FETCH_PEERS fetch mode exists. It’s an optional performance booster for the common case of selecting related objects for every peer in a QuerySet.