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