Thursday, July 27, 2017

Django Admin Inline Duplicate Queries , Slows view

Hi, 

While displaying an object with human readable name in django admin view
Debug_toolbar tells me that sql queries are being duplicated upto 100 times whenever a foreign key is part of the model and rendered in human readable format 

Eg this code renders admin panel slow if there are lot of phone number and phone owners. 

class Phone(models.Model): phone_number = models.CharField(max_length=25, verbose_name="Номер телефона") phone_owner = models.ForeignKey(Owner, verbose_name="Владелец телефона") class Meta: verbose_name = 'Телефон' verbose_name_plural = 'Телефоны' def __unicode__(self): return unicode(self.phone_owner) + " " + self.phone_number
If we omit phone owner from return , the queries become significantly reduced. 

I am using the default admin interface and not using custom ModelAdmin for all the models, should we customise inline views to optimise the queries?

What is the best way to avoid slowing down the queries and also being able to display information in admin portal? 

Is working with select_related and prefetch the only solution to this issue ? as mentioned in answers like these  


This has been discussed in an older thread in this group as well . 


Regards,
Ravi


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ba20ba9e-de90-4cee-bab6-44afd904dde2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment