apps.AppConfig.get_model()

AppConfig.get_model(model_name) [source] Returns the Model with the given model_name. Raises LookupError if no such model exists in this application. model_name is case-insensitive.

admin.TabularInline

class TabularInline [source]

Advanced tutorial: How to write reusable apps

This advanced tutorial begins where Tutorial 7 left off. We’ll be turning our Web-poll into a standalone Python package you can reuse in new projects and share with other people. If you haven’t recently completed Tutorials 1–7, we encourage you to review these so that your example project matches the one described below. Reusability matters It’s a lot of work to design, build, test and maintain a web application. Many Python and Django projects share common problems. Wouldn’t it be great if we

admin.views.decorators.staff_member_required()

staff_member_required(redirect_field_name='next', login_url='admin:login') [source] This decorator is used on the admin views that require authorization. A view decorated with this function will having the following behavior: If the user is logged in, is a staff member (User.is_staff=True), and is active (User.is_active=True), execute the view normally. Otherwise, the request will be redirected to the URL specified by the login_url parameter, with the originally requested path in a query str

Aggregation

The topic guide on Django’s database-abstraction API described the way that you can use Django queries that create, retrieve, update and delete individual objects. However, sometimes you will need to retrieve values that are derived by summarizing or aggregating a collection of objects. This topic guide describes the ways that aggregate values can be generated and returned using Django queries. Throughout this guide, we’ll refer to the following models. These models are used to track the invent

admin.StackedInline

class StackedInline [source] The admin interface has the ability to edit models on the same page as a parent model. These are called inlines. Suppose you have these two models: from django.db import models class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): author = models.ForeignKey(Author, on_delete=models.CASCADE) title = models.CharField(max_length=100) You can edit the books authored by an author on the author page. You add inlines t

admin.models.LogEntry.user

LogEntry.user The user (an AUTH_USER_MODEL instance) who performed the action.

admin.register()

register(*models, site=django.admin.sites.site) [source] There is also a decorator for registering your ModelAdmin classes: from django.contrib import admin from .models import Author @admin.register(Author) class AuthorAdmin(admin.ModelAdmin): pass It is given one or more model classes to register with the ModelAdmin and an optional keyword argument site if you are not using the default AdminSite: from django.contrib import admin from .models import Author, Reader, Editor from myproje

admin.models.LogEntry.get_edited_object()

LogEntry.get_edited_object() A shortcut that returns the referenced object.

admin.models.LogEntry.object_repr

LogEntry.object_repr The object`s repr() after the modification.