Reference Generic date views
classMonthArchiveView[source] : A monthly archive page showing all objects in a given month. Objects with a date in the future are not displayed unless you set allow_future to True.
705 sections in Django 5.1 Search all versions →
Reference Generic date views
classMonthArchiveView[source] : A monthly archive page showing all objects in a given month. Objects with a date in the future are not displayed unless you set allow_future to True.
Reference Generic date views
classTodayArchiveView[source] : A day archive page showing all objects for today. This is exactly the same as django.views.generic.dates.DayArchiveView, except today’s date is used instead of the year/month/day arguments.
Reference Generic display views
classdjango.views.generic.detail.DetailView : While this view is executing, self.object will contain the object that the view is operating upon. classdjango.views.generic.detail.BaseDetailView : A base view for displaying a single object.
Reference Built-in class-based views API
Most generic views require the queryset key, which is a QuerySet instance; see Making queries for more information about QuerySet objects.
Reference Editing mixins
classdjango.views.generic.edit.ModelFormMixin : A form mixin that works on ModelForms, 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 Single object mixins
If [`context_object_name`](#django.views.generic.detail.SingleObjectMixin.context_object_name) is not set, the context name will be constructed from the `model_name` of the model that the queryset is composed from. For example, the model `Article` would have context object named `'article'`.
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
action(*,permissions=None,description=None)[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 objects
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 objects
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 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 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. This is required.
Reference The Django admin site AdminSite objects
AdminSite.register(model_or_iterable,admin_class=None,**options)[source] : Registers the given model class (or iterable of classes) with the given admin_class. admin_class defaults to ModelAdmin (the default admin options). If keyword arguments are given – e.g.
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).