May 2018
Beginner to intermediate
526 pages
11h 57m
English
Let's add the order models to the administration site. Edit the admin.py file of the orders application to make it look like this:
from django.contrib import adminfrom .models import Order, OrderItemclass OrderItemInline(admin.TabularInline): model = OrderItem raw_id_fields = ['product']@admin.register(Order)class OrderAdmin(admin.ModelAdmin): list_display = ['id', 'first_name', 'last_name', 'email', 'address', 'postal_code', 'city', 'paid', 'created', 'updated'] list_filter = ['paid', 'created', 'updated'] inlines = [OrderItemInline]
We use a ModelInline class for the OrderItem model to include it as an inline in the OrderAdmin class. An inline allows you to include a model on the same edit ...
Read now
Unlock full access