In my E-commerce Project, Everytime I click on the orders model in Django Admin, it takes a while to load, so I thought the reason might be because of the many orders in the page which is not paginated.
So my question is how to paginate the order.model in Django Admin, second is this the reason why it is the only page that is taking a while to load or might there be another reason that I should be thinking of?
Here is the models.py
class Order(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,
on_delete=models.CASCADE)
ref_code = models.CharField(max_length=20, unique=True, blank=True, null=True)
items = models.ManyToManyField(OrderItem)
---------------------------------------
Here is the admin.py
class OrderAdmin(admin.ModelAdmin):
list_display = ['id', 'user', 'ordered', 'ordered_date', 'coupon', 'payment', 'shipping_address', 'status',
'refund_requested', 'refund_granted', 'ref_code']
list_display_links = [
'id',
]
list_editable = ['status']
list_filter = ['ordered', 'ordered_date', 'refund_requested', 'refund_granted', 'status']
search_fields = [
'user__username',
'ref_code'
]
actions = [make_refund_accepted]
There is already pagination in default and default page size is 100
You can reduce/change it to any number eg: 20 by list_per_page
class OrderAdmin(admin.ModelAdmin):
list_display = ['id', 'user', 'ordered', 'ordered_date', 'coupon', 'payment', 'shipping_address', 'status',
'refund_requested', 'refund_granted', 'ref_code']
list_display_links = [
'id',
]
list_editable = ['status']
list_filter = ['ordered', 'ordered_date', 'refund_requested', 'refund_granted', 'status']
search_fields = [
'user__username',
'ref_code'
]
actions = [make_refund_accepted]
list_per_page = 20
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.