I have a model with a table that has around 5 million records. Currently django admin is very slow for the list display page. It can take a minute or more for the page to load.
Is there a way to optimize the list display page? And make it load under 10 seconds? Thanks in advance.
models.py
class Notification(models.Model):
id = models.AutoField(primary_key=True)
token = models.ForeignKey(Token)
alert = models.ForeignKey(Alert)
created_at = models.DateTimeField(auto_now=True)
is_sent = models.BooleanField(default=False)
is_processed = models.BooleanField(default=False)
error_sending = models.BooleanField(default=False)
# ...
def __unicode__(self):
return u'%s' % (self.id )
admin.py
class AppNotification(admin.ModelAdmin):
fields = ['is_sent','is_processed','error_sending']
#
list_display = ('token_code','is_sent','is_processed')
#
search_fields = ('token','alert')
#
list_select_related = ('alert', 'token')
#
list_per_page = 30
admin.site.register(Notification,AppNotification)
Django Version 1.6
Solution
class AppNotification(admin.ModelAdmin):
readonly_fields = ('token','alert')
fields = ['is_sent','is_processed','error_sending','token','alert']
#
list_display = ('id','is_sent','is_processed','error_sending')
#
search_fields = ['token__token']
#
list_per_page = 50
admin.site.register(Notification,AppNotification)
The issue is probably the join on the token foreign key. You may want to remove that token_code from the list_display, if possible and completely remove your list_select_related property,
At the very least, remove the 'alert' from list_select_related property, since you don't even use it in the list view.
Remove:
list_select_related = ('alert', 'token')
list_select_related will call select_related. But looking up all related alerts an tokens is redundant.
Why did you truncate the Notification model?
# ... <-- Maybe there is inefficient logic over here!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With