Reference
Model field reference
Field types
If you want to be able to modify this field, set the following instead of auto_now_add=True: The default form widget for this field is a DateInput. The admin adds a JavaScript calendar, and a shortcut for “Today”.
4.2
5.0
5.1
5.2
6.0
Reference
QuerySet API reference
QuerySet APIMethods that return new QuerySets
where / tables You can define explicit SQL WHERE clauses — perhaps to perform non-explicit joins — by using where. You can manually add tables to the SQL FROM clause by using tables.
4.2
5.0
5.1
5.2
6.0
Topic guide
Using the Django authentication system
Authentication in web requestsRedirecting unauthorized requests in class-based views
If your AUTH_USER_MODEL inherits from AbstractBaseUser or implements its own get_session_auth_hash() method, authenticated sessions will include the hash returned by this function. In the AbstractBaseUser case, this is an HMAC of the password field.
4.2
5.0
5.1
5.2
6.0
Topic guide
Introduction to class-based views
… Django uses to build class-based generic views are built for maximum flexibility, and as such have many hooks in the form of default method implementations and attributes that you are unlikely to be concerned with in the simplest use cases. …
4.2
5.0
5.1
5.2
6.0
Topic guide
Introduction to class-based views
… is worth noting that what your method returns is identical to what you return from a function-based view, namely some form of HttpResponse. This means that http shortcuts or TemplateResponse objects are valid to use inside a class-based view. While …
4.2
5.0
5.1
5.2
6.0
Topic guide
Using mixins with class-based views
Building up Django’s generic class-based views
The _detail part can be changed by setting template_name_suffix on a subclass to something else. (For instance, the generic edit views use _form for create and update views, and _confirm_delete for delete views.)
4.2
5.0
5.1
5.2
6.0
Topic guide
Using mixins with class-based views
First, let’s look at a naive attempt to combine DetailView with FormMixin to enable us to POST a Django Form to the same URL as we’re displaying an object using DetailView.
4.2
5.0
5.1
5.2
6.0
Topic guide
Models
FieldsRelationships
It doesn’t matter which model has the ManyToManyField, but you should only put it in one of the models – not both. Generally, ManyToManyField instances should go in the object that’s going to be edited on a form.
4.2
5.0
5.1
5.2
6.0
Topic guide
Creating forms from models
Model formsets
As with regular formsets, you can use the max_num and extra parameters to modelformset_factory() to limit the number of extra forms displayed.
4.2
5.0
5.1
5.2
6.0
Topic guide
Time zones
Concepts
Most websites that care about time zones ask users in which time zone they live and store this information in the user’s profile. For anonymous users, they use the time zone of their primary audience or UTC.
4.2
5.0
5.1
5.2
6.0
Topic guide
Translation
Internationalization: in template code
… within the translation block. Examples: You can use multiple expressions inside a single blocktranslate tag: NOTE: The previous more verbose format is still supported: > {% blocktranslate with book|title as book_t and author|title as author_t %} Other block tags (for …
4.2
5.0
5.1
5.2
6.0
Topic guide
Translation
Localization: how to create language files
NOTE: If you’re using Windows and need to install the GNU gettext utilities so > makemessages works, see gettext on Windows for more > information.
4.2
5.0
5.1
5.2
6.0
Topic guide
Testing tools
Provided test case classes
classTestCase[source] This is the most common class to use for writing tests in Django. It inherits from TransactionTestCase (and by extension SimpleTestCase). If your Django application doesn’t use a database, use SimpleTestCase.
4.2
5.0
5.1
5.2
6.0
Topic guide
Testing tools
Provided test case classes
… time. In particular, this means that in some cases > (for example, just after clicking a link or submitting a form), you might > need to check that a response is received by Selenium and that the next > page …
4.2
5.0
5.1
5.2
6.0
Topic guide
Testing tools
Test cases features
… | | --- | --- | | USE_TZ, TIME_ZONE | Databases timezone | | TEMPLATES | Template engines | | FORM_RENDERER | Default renderer | | SERIALIZATION_MODULES | Serializers cache | | LOCALE_PATHS, LANGUAGE_CODE | Default translation and loaded translations …
5.1
5.2
6.0
Index
… backends.smtp.EmailBackend (class in django.core.mail) - BadRequest - bands (GDALRaster attribute) - base36_to_int() (in module django.utils.http) - base_field (ArrayField attribute) - (django.contrib.postgres.forms.BaseRangeField attribute) - (RangeField attribute) - (SimpleArrayField attribute) - (SplitArrayField attribute) - base_layer (BaseGeometryWidget attribute) - (OpenLayersWidget attribute) - (OSMWidget …
5.2
6.0
dev
Internals
Django Deprecation Timeline
The undocumented BaseForm._html_output() method will be removed. The ability to return a str, rather than a SafeString, when rendering an ErrorDict and ErrorList will be removed. See the Django 4.1 release notes for more details on these changes.
5.2
Internals
Django Deprecation Timeline
The following private APIs will be removed from django.db.models.options.Options (Model._meta): get_field_by_name() get_all_field_names() get_fields_with_model() get_concrete_fields_with_model() get_m2m_with_model() get_all_related_objects() get_all_related_objects_with_model() get_all_related_many_to_many_objects() get_all_related_m2m_objects_with_model() The error_message argument of django.forms.RegexField will be removed. The unordered_list filter will no longer support old style lists.
5.0
5.1
5.2
Internals
Django Deprecation Timeline
The following private APIs will be removed from django.db.models.options.Options (Model._meta): get_field_by_name() get_all_field_names() get_fields_with_model() get_concrete_fields_with_model() get_m2m_with_model() get_all_related_objects() get_all_related_objects_with_model() get_all_related_many_to_many_objects() get_all_related_m2m_objects_with_model() The error_message argument of django.forms.RegexField will be removed. The unordered_list filter will no longer support old style lists.
4.2
5.0
5.1
Topic guide
Customizing authentication in Django
Substituting a custom User model
Django’s built-in forms and views make certain assumptions about the user model that they are working with. The following forms are compatible with any subclass of AbstractBaseUser: AuthenticationForm: Uses the username field specified by USERNAME_FIELD.
4.2
5.0