Oh, yah, sure. Sorry.
class Host(models.Model):
name = models.CharField(max_length=128, unique=True)
class Account(models.Model):
host = models.ForeignKey(Host, related_name="accounts")
name = models.CharField(max_length=128)
class AccountAdmin(admin.ModelAdmin):
list_display = ('name', 'host')
list_editable = ('host',)
list_per_page = 25
admin.site.register(Account, AccountAdmin)
Rendering the FK widgets here requires n*m=25*1=25 database queries:
Form: SELECT "hosts_host"."id", "hosts_host"."name" FROM "hosts_host"
ORDER BY "hosts_host"."name" ASC
Total time: 330 ms
Numer of queries: 25
Twenty five queries is, of course, not a big deal. However, the
default changelist is n=100, and with m=4 this becomes a real problem.
If you comment out the list_editable line or use the fix below
( formfield_overrides = {models.ForeignKey:{'widget':
CachedSelect()}} ), the number of queries returns to O(1).
The jist of what I am wondering is if the changelist is going to allow
editable ForeignKeys, should it be caching the choices rather than
hitting the database every time?
On Jun 29, 7:14 pm, Jeremy Dunck <
jdu...@gmail.com> wrote: