From 97a7543f9e9e06204706b0d932608bd7933f56c4 Mon Sep 17 00:00:00 2001 From: Raz Date: Wed, 7 May 2025 07:18:13 +0200 Subject: [PATCH] show email in order admin panel --- shop/admin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/shop/admin.py b/shop/admin.py index 9c61ae7..58dd0ee 100644 --- a/shop/admin.py +++ b/shop/admin.py @@ -47,11 +47,17 @@ class ShippingAddressAdmin(admin.ModelAdmin): @admin.register(Order) class OrderAdmin(admin.ModelAdmin): - list_display = ('id', 'date_ordered', 'status', 'total_price', 'get_shipping_address') + list_display = ('id', 'get_email', 'date_ordered', 'status', 'total_price', 'get_shipping_address') inlines = [OrderItemInline] list_filter = ('status', 'payment_status') readonly_fields = ('shipping_address_details',) + def get_email(self, obj): + if obj.guest_user: + return obj.guest_user.email + else: + return obj.user.email + def get_shipping_address(self, obj): if obj.shipping_address: return f"{obj.shipping_address.street_address}, {obj.shipping_address.city}"