Re: Improve Performance in Admin ManyToMany

2015-05-20 Thread Timothy W. Cook
*SOLVED:* The correct method name is *formfield_for_manytomany * instead of *formfield_for_many_to_many* *def formfield_for_manytomany(self, db_field, *args, **kwargs):* *formfield = super(ClusterAdmin, self).formfield_for_manytomany(db_field, *args, **kwargs)* *if db_field.name

Re: Improve Performance in Admin ManyToMany

2015-05-17 Thread Timothy W. Cook
On Sun, May 17, 2015 at 4:20 PM, Erik Cederstrand wrote: > > I just noticed you have a typo: > > if db_field.name in ['cluster', ... > > should be: > > if db_field.name in ['clusters', ... > > according to your model definition. > > ​Thanks Erik. Yes, that was

Re: Improve Performance in Admin ManyToMany

2015-05-17 Thread Erik Cederstrand
> Den 15/05/2015 kl. 20.54 skrev Timothy W. Cook : > > def formfield_for_many_to_many(self, db_field, *args, **kwargs): > formfield = super(ClusterAdmin, > self).formfield_for_many_to_many(db_field, *args, **kwargs) > if db_field.name in >

Re: Improve Performance in Admin ManyToMany

2015-05-16 Thread Timothy W. Cook
On Sat, May 16, 2015 at 5:27 PM, Erik Cederstrand wrote: > > > Den 15/05/2015 kl. 20.54 skrev Timothy W. Cook : > > > > def formfield_for_many_to_many(self, db_field, *args, **kwargs): > > formfield = super(ClusterAdmin, >

Re: Improve Performance in Admin ManyToMany

2015-05-16 Thread Erik Cederstrand
> Den 15/05/2015 kl. 20.54 skrev Timothy W. Cook : > > def formfield_for_many_to_many(self, db_field, *args, **kwargs): > formfield = super(ClusterAdmin, > self).formfield_for_many_to_many(db_field, *args, **kwargs) > if db_field.name in >

Re: Improve Performance in Admin ManyToMany

2015-05-15 Thread Timothy W. Cook
On Fri, May 15, 2015 at 7:25 AM, Erik Cederstrand wrote: > > > I wonder if there is another approach that I can use to solve this? > > Does the suggestion to append select_related() / prefetch_related() to the > queryset in your admin view not work? > ​If I

Re: Improve Performance in Admin ManyToMany

2015-05-15 Thread Erik Cederstrand
> Den 14/05/2015 kl. 22.19 skrev Timothy W. Cook : > > That is exactly the problem Simon. Everyone of those models reference a > model called Project. I did this so that when the items are displayed in the > selects, the user knows which project it is from. In the interim I

Re: Improve Performance in Admin ManyToMany

2015-05-14 Thread Timothy W. Cook
That is exactly the problem Simon. Everyone of those models reference a model called Project. I did this so that when the items are displayed in the selects, the user knows which project it is from. In the interim I guess I'll remove the call to Project from the __str__ I wonder if there is

Re: Improve Performance in Admin ManyToMany

2015-05-14 Thread Simon Charette
The last example should read: if db_field.name == 'baz': Le jeudi 14 mai 2015 11:14:24 UTC-4, Simon Charette a écrit : > > It's a bit hard to tell without your model definition and the executed > queries but is it possible that the string representation method (__str__, > __unicode__) of one

Re: Improve Performance in Admin ManyToMany

2015-05-14 Thread Simon Charette
I meant if db_field.name == 'bars': Sorry for noise... Le jeudi 14 mai 2015 11:15:49 UTC-4, Simon Charette a écrit : > > The last example should read: > > if db_field.name == 'baz': > > > > Le jeudi 14 mai 2015 11:14:24 UTC-4, Simon Charette a écrit : >> >> It's a bit hard to tell without your

Re: Improve Performance in Admin ManyToMany

2015-05-14 Thread Simon Charette
It's a bit hard to tell without your model definition and the executed queries but is it possible that the string representation method (__str__, __unicode__) of one the models referenced by a M2M access another related model during construction? e.g. from django.db import models class

Re: Improve Performance in Admin ManyToMany

2015-05-14 Thread Timothy W. Cook
It isn't that the individual queries are very slow. But that there are so many of them. Attached is a screenshot of DjDT. I see that I am not using a cache at all. This was after doing a reload of the same standard Django admin/change_form.html. On Wed, May 13, 2015 at 1:58 PM, Tim Graham

Re: Improve Performance in Admin ManyToMany

2015-05-13 Thread Tim Graham
Are you sure it's the query that's slow and not the template rendering and/or JavaScript performance? On Wednesday, May 13, 2015 at 12:32:50 PM UTC-4, Timothy W. Cook wrote: > > I have a model with 13 M2M relations and some of those have a few thousand > instances. > This renders rather slowly

Improve Performance in Admin ManyToMany

2015-05-13 Thread Timothy W. Cook
I have a model with 13 M2M relations and some of those have a few thousand instances. This renders rather slowly in the Admin. Thinking about improvements I wonder if it will help to setup prefetch_related queries https://docs.djangoproject.com/en/1.8/ref/models/querysets/#prefetch-related