Web frameworks · Beginner · 24 min
Customise the Django admin for your staff
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Python 3.15 · Django 6.1
You will turn the default Django 6.1 admin into an order desk where a support person can search, filter and update orders, while payment details, customer records and deletion stay out of their reach.
On this page
The Django admin is built for whoever writes the code. Out of the box it lists rows by their name, lets every staff member see every model they have rights to, and offers a delete button on almost everything. That is fine for you, and risky for a support person who answers customer calls all day.
In this tutorial you build a small shop with customers, orders and order items, then shape its admin around one job: a customer rings with a phone number or an order number, and the support person finds the order, checks what was bought and moves it along. They should not browse the customer list, see payment references or delete anything. You do all of it with standard ModelAdmin options, one admin action, one custom permission and a staff group, and you finish with tests that prove each rule.
If you have not built a Django project before, start with create your first Django 6 app, which covers uv, startproject and migrations in more detail.
Step 1 · Create the shop project and its models
Make a throwaway folder for the demo, start a uv project and add Django 6.1:
mkdir -p ~/staff-admin-demo
cd ~/staff-admin-demo
uv init --no-package
rm main.py
uv add "django>=6.1,<6.2"
uv run django-admin startproject config .
uv run python manage.py startapp shopRegister the app by appending to the settings file:
cat >> config/settings.py <<'PY'
INSTALLED_APPS += ["shop"]
PYNow the data. A customer places orders, and each order has one or more items. The order also holds a payment reference from the payment provider, which only finance staff need. The permissions line in Meta adds a custom permission next to the four Django creates for every model (add, change, delete and view). You will use it in a later step to decide who sees that reference. Replace shop/models.py:
cat > shop/models.py <<'PY'
from django.db import models
class Customer(models.Model):
name = models.CharField(max_length=120)
email = models.EmailField()
phone = models.CharField(max_length=20, help_text="International format, such as +2348031234567")
def __str__(self):
return self.name
class Order(models.Model):
class Status(models.TextChoices):
PENDING = "pending", "Pending"
PAID = "paid", "Paid"
SHIPPED = "shipped", "Shipped"
DELIVERED = "delivered", "Delivered"
CANCELLED = "cancelled", "Cancelled"
number = models.CharField(max_length=20, unique=True)
customer = models.ForeignKey(Customer, on_delete=models.PROTECT, related_name="orders")
status = models.CharField(max_length=20, choices=Status, default=Status.PENDING)
currency = models.CharField(max_length=3, default="NGN")
payment_reference = models.CharField(max_length=60, blank=True)
notes = models.TextField(blank=True)
created = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ["-created"]
permissions = [("view_payment_details", "Can see payment details")]
def __str__(self):
return self.number
class OrderItem(models.Model):
order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name="items")
product = models.CharField(max_length=120)
quantity = models.PositiveIntegerField(default=1)
unit_price = models.DecimalField(max_digits=10, decimal_places=2)
def __str__(self):
return f"{self.quantity} x {self.product}"
PY
uv run python manage.py makemigrations shop
uv run python manage.py migrateAdd some orders to work with. manage.py shell runs Python that you pipe into it. The update() call backdates each order so the date navigation in the next step has more than one month to show:
uv run python manage.py shell <<'PY'
from datetime import UTC, datetime
from decimal import Decimal
from shop.models import Customer, Order, OrderItem
chidi = Customer.objects.create(name="Chidi Nwosu", email="chidi@example.com", phone="+2348031234567")
wanjiru = Customer.objects.create(name="Wanjiru Kamau", email="wanjiru@example.com", phone="+254712345678")
sipho = Customer.objects.create(name="Sipho Dlamini", email="sipho@example.com", phone="+27821234567")
orders = [
("PD-1001", chidi, "paid", "NGN", "PAY-7F3A91", datetime(2026, 10, 3, 9, 30, tzinfo=UTC),
[("Solar lamp", 2, "18500.00"), ("Phone charger", 1, "6500.00")]),
("PD-1002", wanjiru, "pending", "KES", "", datetime(2026, 10, 21, 14, 5, tzinfo=UTC),
[("Water filter", 1, "4200.00")]),
("PD-1003", sipho, "paid", "ZAR", "PAY-91C2D4", datetime(2026, 11, 4, 11, 0, tzinfo=UTC),
[("Backpack", 1, "899.00")]),
("PD-1004", chidi, "shipped", "NGN", "PAY-2B8E07", datetime(2026, 11, 12, 16, 45, tzinfo=UTC),
[("Solar lamp", 1, "18500.00")]),
]
for number, customer, status, currency, reference, created, items in orders:
order = Order.objects.create(
number=number, customer=customer, status=status,
currency=currency, payment_reference=reference,
)
Order.objects.filter(pk=order.pk).update(created=created)
for product, quantity, price in items:
OrderItem.objects.create(order=order, product=product, quantity=quantity, unit_price=Decimal(price))
print(Order.objects.count(), "orders,", OrderItem.objects.count(), "items")
PYCheck it worked
makemigrations lists + Create model Customer, + Create model Order and + Create model OrderItem, and migrate ends with Applying shop.0001_initial... OK. The shell prints 4 orders, 5 items.
Step 2 · Make the order list searchable
Registering a model with no options gives a list that shows only PD-1001, PD-1002 and so on. A support person needs to see the customer and the status at a glance, narrow the list down and search by whatever the caller gives them. Create shop/admin.py:
cat > shop/admin.py <<'PY'
from django.contrib import admin
from .models import Customer, Order
@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
list_display = ["name", "email", "phone"]
search_fields = ["name", "email", "phone"]
@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
list_display = ["number", "customer", "status", "currency", "created"]
list_filter = ["status", "currency", "created"]
search_fields = ["number", "customer__name", "customer__phone", "customer__email"]
date_hierarchy = "created"
list_select_related = ["customer"]
list_per_page = 25
PY
uv run python manage.py checkWhat each option does:
list_displaypicks the columns. The first one links to the order's page.list_filteradds a sidebar of filters. Status and currency become lists of their values, and a date field gets ranges such as "Past 7 days".search_fieldsadds a search box. The double underscore follows the foreign key, so typing part of a phone number finds orders whose customer has that number. Support never has to open the customer records to do it.date_hierarchyadds year and month links above the list.list_select_relatedfetches each order's customer in the same query, instead of one extra query per row.list_per_pagekeeps each page small. Many support staff work from low-end Android phones on prepaid data, and 25 rows load faster than the default 100.
Phone numbers are stored in international format, so a caller who says "0803 123 4567" can be found by typing 8031234567, the part both forms share. If your customers' names use accented letters, such as Yoruba or Afrikaans names, note that SQLite only ignores case for plain ASCII letters. PostgreSQL behaves as you would expect.
Create your own administrator account. The command asks for a username, an email address and a password, and the password does not show as you type:
uv run python manage.py createsuperuserStart the development server, and use a second terminal for the commands that follow:
uv run python manage.py runservercurl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8000/admin/login/Check it worked
check prints System check identified no issues (0 silenced). and curl prints 200. Log in at http://127.0.0.1:8000/admin/ and open Orders. You see four rows with number, customer, status, currency and date, a filter sidebar on the right and month links above the list. All the orders are from 2026, so Django skips the year and offers October 2026 and November 2026. Click October 2026, and only PD-1001 and PD-1002 remain. Search for 8031234567 and you get Chidi's two orders.
Step 3 · Show items and lock fields on the order page
Open an order now and you see its fields, but not what the customer bought. Items live in their own table, and an inline puts them on the order's page. Some fields should also be read-only: once an order exists, its number, customer and currency do not change, and the creation date and total are computed. Replace shop/admin.py:
cat > shop/admin.py <<'PY'
from django.contrib import admin
from .models import Customer, Order, OrderItem
@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
list_display = ["name", "email", "phone"]
search_fields = ["name", "email", "phone"]
class OrderItemInline(admin.TabularInline):
model = OrderItem
extra = 0
fields = ["product", "quantity", "unit_price"]
@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
list_display = ["number", "customer", "status", "currency", "created"]
list_filter = ["status", "currency", "created"]
search_fields = ["number", "customer__name", "customer__phone", "customer__email"]
date_hierarchy = "created"
list_select_related = ["customer"]
list_per_page = 25
inlines = [OrderItemInline]
readonly_fields = ["created", "order_total"]
def get_readonly_fields(self, request, obj=None):
fields = list(super().get_readonly_fields(request, obj))
if obj is not None:
fields += ["number", "customer", "currency"]
return fields
@admin.display(description="Total")
def order_total(self, obj):
if obj.pk is None:
return "-"
total = sum(item.quantity * item.unit_price for item in obj.items.all())
return f"{obj.currency} {total:,.2f}"
PY
uv run python manage.py checkTabularInline shows the items as rows of a small table, and extra = 0 stops Django adding three empty rows for new items every time the page opens. readonly_fields can name model fields or methods on the admin class, which is how the computed total appears. get_readonly_fields adds the fields that are fixed only once the order exists, so you can still fill them in when you add a new order yourself.
Check the total for PD-1001 from the shell. Two solar lamps at 18,500 and one charger at 6,500 should make 43,500:
uv run python manage.py shell -c "
from shop.admin import OrderAdmin
from shop.models import Order
from django.contrib import admin
print(OrderAdmin(Order, admin.site).order_total(Order.objects.get(number='PD-1001')))
"Check it worked
The shell prints NGN 43,500.00. In the browser, refresh PD-1001: the items table lists the solar lamp and the phone charger, the total reads NGN 43,500.00, and number, customer and currency are plain text rather than form fields. Status, payment reference and notes can still be edited.
Step 4 · Add an action that marks orders as shipped
Every morning someone moves a stack of paid orders to shipped. Opening them one at a time is slow. An admin action works on the rows ticked in the list. Add the messages import and the action to shop/admin.py by replacing the file:
cat > shop/admin.py <<'PY'
from django.contrib import admin, messages
from .models import Customer, Order, OrderItem
@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
list_display = ["name", "email", "phone"]
search_fields = ["name", "email", "phone"]
class OrderItemInline(admin.TabularInline):
model = OrderItem
extra = 0
fields = ["product", "quantity", "unit_price"]
@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
list_display = ["number", "customer", "status", "currency", "created"]
list_filter = ["status", "currency", "created"]
search_fields = ["number", "customer__name", "customer__phone", "customer__email"]
date_hierarchy = "created"
list_select_related = ["customer"]
list_per_page = 25
inlines = [OrderItemInline]
readonly_fields = ["created", "order_total"]
actions = ["mark_shipped"]
def get_readonly_fields(self, request, obj=None):
fields = list(super().get_readonly_fields(request, obj))
if obj is not None:
fields += ["number", "customer", "currency"]
return fields
@admin.display(description="Total")
def order_total(self, obj):
if obj.pk is None:
return "-"
total = sum(item.quantity * item.unit_price for item in obj.items.all())
return f"{obj.currency} {total:,.2f}"
@admin.action(description="Mark selected paid orders as shipped", permissions=["change"])
def mark_shipped(self, request, queryset):
updated = queryset.filter(status=Order.Status.PAID).update(status=Order.Status.SHIPPED)
skipped = queryset.count() - updated
self.message_user(request, f"{updated} order(s) marked as shipped.", messages.SUCCESS)
if skipped:
self.message_user(request, f"{skipped} order(s) were not paid and were left alone.", messages.WARNING)
PY
uv run python manage.py checkTwo choices keep the action safe. It filters to paid orders first, so ticking a pending order by mistake does not ship it, and it tells the user what it skipped. permissions=["change"] hides the action from anyone who can only view orders. Note that update() writes straight to the database: it does not call each order's save() method or add entries to the admin's history.
Check it worked
check reports no issues. In the order list, tick PD-1002 (pending) and PD-1003 (paid), choose Mark selected paid orders as shipped in the action menu and press Go. A green message says 1 order(s) marked as shipped., a yellow one says 1 order(s) were not paid and were left alone., and only PD-1003 now shows Shipped.
Step 5 · Hide payment details from staff who do not need them
The payment reference is useful to finance and a risk in anyone else's hands. Django's permissions apply to whole models, so to hide one field you check the custom view_payment_details permission yourself and drop the field when the user lacks it. Superusers pass every permission check, so you keep seeing it. Add a get_fields method to OrderAdmin by rewriting the file:
cat > shop/admin.py <<'PY'
from django.contrib import admin, messages
from .models import Customer, Order, OrderItem
@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
list_display = ["name", "email", "phone"]
search_fields = ["name", "email", "phone"]
class OrderItemInline(admin.TabularInline):
model = OrderItem
extra = 0
fields = ["product", "quantity", "unit_price"]
@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
list_display = ["number", "customer", "status", "currency", "created"]
list_filter = ["status", "currency", "created"]
search_fields = ["number", "customer__name", "customer__phone", "customer__email"]
date_hierarchy = "created"
list_select_related = ["customer"]
list_per_page = 25
inlines = [OrderItemInline]
readonly_fields = ["created", "order_total"]
actions = ["mark_shipped"]
def get_fields(self, request, obj=None):
fields = super().get_fields(request, obj)
if not request.user.has_perm("shop.view_payment_details"):
fields = [name for name in fields if name != "payment_reference"]
return fields
def get_readonly_fields(self, request, obj=None):
fields = list(super().get_readonly_fields(request, obj))
if obj is not None:
fields += ["number", "customer", "currency"]
return fields
@admin.display(description="Total")
def order_total(self, obj):
if obj.pk is None:
return "-"
total = sum(item.quantity * item.unit_price for item in obj.items.all())
return f"{obj.currency} {total:,.2f}"
@admin.action(description="Mark selected paid orders as shipped", permissions=["change"])
def mark_shipped(self, request, queryset):
updated = queryset.filter(status=Order.Status.PAID).update(status=Order.Status.SHIPPED)
skipped = queryset.count() - updated
self.message_user(request, f"{updated} order(s) marked as shipped.", messages.SUCCESS)
if skipped:
self.message_user(request, f"{skipped} order(s) were not paid and were left alone.", messages.WARNING)
PY
uv run python manage.py checkThe admin builds both the page and the form from get_fields, so a field removed there is neither shown nor accepted when the form is saved. Someone who edits the page's HTML to send a payment_reference value cannot change it. Keep the field out of list_display, list_filter and search_fields too, or it would leak through the list instead.
Check it worked
check reports no issues. Logged in as your superuser, PD-1001 still shows the payment reference PAY-7F3A91. You test the other side in the last step, once there is a support user to log in as.
Step 6 · Create a Support group with limited permissions
Give permissions to groups, not to individual people. When someone joins or leaves support you change their group, and the rules stay in one place. You can tick the permissions under Authentication and Authorization → Groups in the admin, but a management command keeps the group's rules in your code, where they are reviewed and can be run again on every server. Create it:
mkdir -p shop/management/commands
cat > shop/management/commands/create_support_group.py <<'PY'
from django.contrib.auth.models import Group, Permission
from django.core.management.base import BaseCommand
SUPPORT_PERMISSIONS = [
"view_order",
"change_order",
"view_orderitem",
]
class Command(BaseCommand):
help = "Create the Support group, or reset its permissions to the list in this file."
def handle(self, *args, **options):
group, created = Group.objects.get_or_create(name="Support")
permissions = Permission.objects.filter(
content_type__app_label="shop", codename__in=SUPPORT_PERMISSIONS
)
group.permissions.set(permissions)
action = "Created" if created else "Updated"
self.stdout.write(f"{action} Support group with {permissions.count()} permissions")
PY
uv run python manage.py create_support_groupThe list is short on purpose. Support can view and change orders and view their items. They get nothing on customers, no delete_order, no add_order, and no view_payment_details. set() replaces whatever the group had before, so running the command again removes permissions someone added by hand.
Now add a support user. is_staff=True lets them log in to the admin at all, and the group decides what they see once inside. This makes the user without a password:
uv run python manage.py shell -c "
from django.contrib.auth.models import Group, User
user, _ = User.objects.get_or_create(username='amina', defaults={'is_staff': True})
user.groups.add(Group.objects.get(name='Support'))
print(user.username, 'is staff:', user.is_staff)
"Set a password for the account. The command prompts for it twice, so it never appears in your shell history:
uv run python manage.py changepassword aminaList the permissions Amina ends up with:
uv run python manage.py shell -c "
from django.contrib.auth.models import User
print(sorted(User.objects.get(username='amina').get_all_permissions()))
"Check it worked
The command prints Created Support group with 3 permissions (or Updated on a second run), and the last command prints ['shop.change_order', 'shop.view_order', 'shop.view_orderitem']. Log out, then log in as amina in a private browser window. The admin home shows only Shop → Orders. Customers and the user and group screens are missing.
Step 7 · Prove what support can and cannot do
Clicking through as Amina shows you the rules once. Tests show them on every change, so a later edit to admin.py that leaks a field fails loudly. Django's test client logs in with force_login, requests the admin pages and checks the HTML that comes back. Replace shop/tests.py:
cat > shop/tests.py <<'PY'
from decimal import Decimal
from io import StringIO
from django.contrib.auth.models import Group, User
from django.core.management import call_command
from django.test import TestCase
from django.urls import reverse
from .models import Customer, Order, OrderItem
class SupportAdminTests(TestCase):
@classmethod
def setUpTestData(cls):
call_command("create_support_group", stdout=StringIO())
cls.support = User.objects.create_user("support-test", is_staff=True)
cls.support.groups.add(Group.objects.get(name="Support"))
cls.boss = User.objects.create_superuser("boss-test", "boss@example.com", None)
chidi = Customer.objects.create(name="Chidi Nwosu", email="chidi@example.com", phone="+2348031234567")
wanjiru = Customer.objects.create(name="Wanjiru Kamau", email="wanjiru@example.com", phone="+254712345678")
cls.paid = Order.objects.create(
number="PD-1001", customer=chidi, status="paid", payment_reference="PAY-7F3A91"
)
cls.pending = Order.objects.create(number="PD-1002", customer=wanjiru, status="pending", currency="KES")
OrderItem.objects.create(order=cls.paid, product="Solar lamp", quantity=2, unit_price=Decimal("18500.00"))
def setUp(self):
self.client.force_login(self.support)
def test_finds_an_order_by_part_of_a_phone_number(self):
response = self.client.get(reverse("admin:shop_order_changelist"), {"q": "8031234567"})
self.assertContains(response, "PD-1001")
self.assertNotContains(response, "PD-1002")
def test_cannot_open_the_customer_list(self):
response = self.client.get(reverse("admin:shop_customer_changelist"))
self.assertEqual(response.status_code, 403)
def test_cannot_delete_orders(self):
response = self.client.get(reverse("admin:shop_order_changelist"))
self.assertContains(response, 'value="mark_shipped"')
self.assertNotContains(response, 'value="delete_selected"')
delete_page = self.client.get(reverse("admin:shop_order_delete", args=[self.paid.pk]))
self.assertEqual(delete_page.status_code, 403)
def test_order_page_shows_items_but_hides_payment_reference(self):
response = self.client.get(reverse("admin:shop_order_change", args=[self.paid.pk]))
self.assertContains(response, "Solar lamp")
self.assertContains(response, "NGN 37,000.00")
self.assertContains(response, 'name="status"')
self.assertNotContains(response, 'name="items-0-quantity"')
self.assertNotContains(response, "PAY-7F3A91")
def test_superuser_still_sees_payment_reference(self):
self.client.force_login(self.boss)
response = self.client.get(reverse("admin:shop_order_change", args=[self.paid.pk]))
self.assertContains(response, "PAY-7F3A91")
def test_mark_shipped_only_moves_paid_orders(self):
response = self.client.post(
reverse("admin:shop_order_changelist"),
{"action": "mark_shipped", "_selected_action": [self.paid.pk, self.pending.pk]},
follow=True,
)
self.assertContains(response, "1 order(s) marked as shipped.")
self.paid.refresh_from_db()
self.pending.refresh_from_db()
self.assertEqual(self.paid.status, "shipped")
self.assertEqual(self.pending.status, "pending")
PY
uv run python manage.py test shopEach test names one rule from this tutorial: search by phone, no customer list, no deletion, items visible but read-only, payment reference hidden from support and shown to a superuser, and an action that only ships paid orders. The test run uses its own empty database, so your demo orders are untouched.
Check it worked
The runner prints Found 6 test(s)., a line of six dots, Ran 6 tests and OK. When you add a new rule to the admin later, add a test for it here in the same change.
When you are done, stop the server with Ctrl+C in its terminal and remove the demo:
cd ~
rm -rf ~/staff-admin-demoNext steps
- Go back over the basics of models, URLs and templates in create your first Django 6 app.
- Give the public side of the site its own accounts with add sign-up and login to a Django app.
- Before staff use the admin over the internet, serve it properly with deploy Django with Gunicorn and Nginx, and turn on two-factor sign-in for staff accounts.
Related tutorials
- How to Create Your First Django 6 AppYou will create a Django 6.1 project with uv on Python 3.15, build a small bookmarks app with a database model, an admin screen, a page and a test, and see how the pieces connect.
- Add sign-up, login and password reset to a Django appYou will have a Django 6.1 notes app with a custom user model, sign-up, login, logout and a working password reset, where each user sees only their own notes and a test suite proves it.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials