Reference Editing mixins
classdjango.views.generic.edit.ModelFormMixin : A form mixin that provides facilities for working with a ModelForm, rather than a standalone form.
743 sections across all versions Narrow to Django 6.0 (current) →
Reference Editing mixins
classdjango.views.generic.edit.ModelFormMixin : A form mixin that provides facilities for working with a ModelForm, rather than a standalone form.
Reference Multiple object mixins
`context_object_name` : Designates the name of the variable to use in the context. `get_queryset()` : Get the list of items for this view. This must be an iterable and may be a queryset (in which queryset-specific behavior will be enabled).
Reference Multiple object mixins
Requires that the view it is mixed with provides self.object_list, the list of object instances that the view is operating on. self.object_list may be, but is not required to be, a QuerySet.
Reference
For example, here’s the user module from Django’s built-in django.contrib.auth app: WARNING: The “delete selected objects” action uses QuerySet.delete() for efficiency reasons, which > has an important caveat: your model’s delete() method will not be > called.
Reference Admin actions Writing actions
Action functions are regular functions that take three arguments: The current ModelAdmin An HttpRequest representing the current request, A QuerySet containing the set of objects selected by the user.
Reference Admin actions Writing actions
Next, we’ll need to inform our ModelAdmin of the action. This works just like any other configuration option.
Reference Admin actions Advanced action techniques
The example above shows the make_published action defined as a function.
Reference Admin actions Advanced action techniques
By default, after an action is performed the user is redirected back to the original change list page. However, some actions, especially more complex ones, will need to return intermediate pages.
Reference Admin actions Advanced action techniques
New in Django 6.1. By default, admin actions are available on the change list page only. You can control where an action appears using the location argument of the @admin.action decorator.
Reference The Django admin site InlineModelAdmin objects
The shared features are: form fieldsets fields formfield_overrides exclude filter_horizontal filter_vertical ordering prepopulated_fields get_fieldsets() get_queryset() radio_fields readonly_fields view_on_site empty_value_display autocomplete_fields raw_id_fields formfield_for_choice_field() formfield_for_foreignkey() formfield_for_manytomany() has_module_permission() The InlineModelAdmin class adds or customizes: InlineModelAdmin.model : The model which the inline is using.
Reference The Django admin site AdminSite objects
Raises django.contrib.admin.exceptions.NotRegistered if a model isn’t registered. AdminSite.get_log_entries(request)[source] : Returns a queryset for the related LogEntry instances, shown on the site index page. This method can be overridden to filter the log entries by other criteria.
Reference The contenttypes framework
Each ContentType instance has methods that allow you to get from a ContentType instance to the model it represents, or to retrieve objects from that model: ContentType.get_object_for_this_type(using=None,**kwargs)[source] : Takes a set of valid lookup arguments for the model the ContentType …
Reference GeoDjango Tutorial Spatial Queries
[4] Import the WorldBorder model, and perform a contains lookup using the pnt_wkt as the parameter: Here, you retrieved a QuerySet with only one model: the border of the United States (exactly what you would expect).
Reference The sitemap framework
items() is a method that returns a sequence or QuerySet of objects. The objects returned will get passed to any callable methods corresponding to a sitemap property (location, lastmod, changefreq, and priority). lastmod should return a datetime.
Reference Databases MySQL notesConnecting to the database
When running concurrent loads, database transactions from different sessions (say, separate threads handling different requests) may interact with each other. These interactions are affected by each session’s transaction isolation level.
Reference Databases MySQL notes
When performing a query on a string type, but with an integer value, MySQL will coerce the types of all values in the table to an integer before performing the comparison.
Reference Databases Oracle notes
LOB columns may not be used in a SELECT DISTINCT list. This means that attempting to use the QuerySet.distinct method on a model that includes TextField columns will result in an ORA-00932 error when run against Oracle.
Reference Query Expressions Built-in ExpressionsSubquery() expressions
There are times when a single column must be returned from a Subquery, for instance, to use a Subquery as the target of an __in lookup.
Reference Query Expressions Built-in Expressions
You can specify multiple windows in the same query which in Django ORM would be equivalent to including multiple expressions in a QuerySet.annotate() call. The ORM doesn’t make use of named windows, instead they are part of the selected columns.
Reference Query Expressions Technical Information
Query expressions implement the query expression API, but also expose a number of extra methods and attributes listed below. All query expressions must inherit from Expression() or a relevant subclass.