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
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
Next, we’ll need to inform our ModelAdmin of the action. This works just like any other configuration option.
Reference
Admin actions
The example above shows the make_published action defined as a function.
Reference
Admin actions
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
NOTE: Added in version 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
Admin actions
action(*,permissions=None,description=None,description_plural=None,location=ActionLocation.CHANGE_LIST)[source] : This decorator can be used for setting specific attributes on custom action functions that can be used with actions:
Reference
The Django admin site
ModelAdmin.list_filter : Set list_filter to activate filters in the right sidebar of the change list page of the admin. ModelAdmin.list_max_show_all : Set list_max_show_all to control how many items can appear on a “Show all” admin change list page.
Reference
The Django admin site
ModelAdmin.raw_id_fields : By default, Django’s admin uses a select-box interface (<select>) for fields that are ForeignKey. Sometimes you don’t want to incur the overhead of having to select all the related instances to display in the drop-down.
Reference
The Django admin site
For example: ModelAdmin.get_search_results(request,queryset,search_term)[source] : The get_search_results method modifies the list of objects displayed into those that match the provided search term. It accepts the request, a queryset that applies the current filters, and the user-provided search term.
Reference
The Django admin site
ModelAdmin.formfield_for_manytomany(db_field,request,**kwargs) : Like the formfield_for_foreignkey method, the formfield_for_manytomany method can be overridden to change the default formfield for a many to many field.
Reference
The Django admin site
This is how list_filter works, for example. The lookups are similar to what’s used in QuerySet.filter() (e.g. [email protected]). Since the lookups in the query string can be manipulated by the user, they must be sanitized to prevent unauthorized data exposure.
Reference
The Django admin site
ModelAdmin.get_changeform_initial_data(request)[source] : A hook for the initial data on admin change forms. By default, fields are given initial values from GET parameters. For instance, ?name=initial_value will set the name field’s initial value to be initial_value.
Reference
The Django admin site
… in the BaseModelAdmin superclass). The shared features are: form fieldsets fields formfield_overrides delete_confirmation_max_display exclude filter_horizontal filter_vertical ordering prepopulated_fields get_exclude() 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 …
Reference
The Django admin site
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
[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 instance: 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
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
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.