May 2018
Beginner to intermediate
526 pages
11h 57m
English
Let's add our models to the administration site so that we can easily manage categories and products. Edit the admin.py file of the shop application and add the following code to it:
from django.contrib import adminfrom .models import Category, Product@admin.register(Category)class CategoryAdmin(admin.ModelAdmin): list_display = ['name', 'slug'] prepopulated_fields = {'slug': ('name',)}@admin.register(Product)class ProductAdmin(admin.ModelAdmin): list_display = ['name', 'slug', 'price', 'available', 'created', 'updated'] list_filter = ['available', 'created', 'updated'] list_editable = ['price', 'available'] prepopulated_fields = {'slug': ('name',)}
Remember that we use the prepopulated_fields ...
Read now
Unlock full access