On Fri, May 15, 2015 at 7:25 AM, Erik Cederstrand <[email protected]
> 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 implemented it correctly, it doesn't have any effect.  I ​get the
same number of queries reported by DjDT and effectively the same amount of
time.

The model called Cluster is the most egregious.
Model:

*class Cluster(Item):*
*    """*
*    The grouping variant of Item, which may contain further instances of
Item, in an ordered list. This*
*    provides the root Item for potentially very complex structures.*
*    """*
*    cluster_subject = models.CharField(_('cluster
subject'),max_length=110, help_text="Enter a text name for this subject of
this cluster.")*
*    clusters = models.ManyToManyField('Cluster',help_text="Select zero or
more Clusters to include in this Cluster. You cannot put a Cluster inside
itself, it will be ignored if you select itself.", blank=True)*
*    dvboolean = models.ManyToManyField(DvBoolean,
related_name='%(class)s_related', help_text="Select zero or more booleans
to include in this Cluster.", blank=True)*
*    dvuri = models.ManyToManyField(DvURI,
related_name='%(class)s_related', help_text="Select zero or more uris to
include in this Cluster.", blank=True)*
*    dvstring = models.ManyToManyField(DvString,
related_name='%(class)s_related', help_text="Select zero or more strings to
include in this Cluster.", blank=True)*
*    dvcodedstring = models.ManyToManyField(DvCodedString,
related_name='%(class)s_related', help_text="Select zero or more coded
strings to include in this Cluster.", blank=True)*
*    dvidentifier = models.ManyToManyField(DvIdentifier,
related_name='%(class)s_related', help_text="Select zero or more
identifiers to include in this Cluster.", blank=True)*
*    dvparsable = models.ManyToManyField(DvParsable,
related_name='%(class)s_related', help_text="Select zero or more parsables
to include in this Cluster.", blank=True)*
*    dvmedia = models.ManyToManyField(DvMedia,
related_name='%(class)s_related', help_text="Select zero or more media
items to include in this Cluster.", blank=True)*
*    dvordinal = models.ManyToManyField(DvOrdinal,
related_name='%(class)s_related', help_text="Select zero or more ordinals
to include in this Cluster.", blank=True)*
*    dvcount = models.ManyToManyField(DvCount,
related_name='%(class)s_related', help_text="Select zero or more counts to
include in this Cluster.", blank=True)*
*    dvquantity = models.ManyToManyField(DvQuantity,
related_name='%(class)s_related', help_text="Select zero or more quantity
items to include in this Cluster.", blank=True)*
*    dvratio = models.ManyToManyField(DvRatio,
related_name='%(class)s_related', help_text="Select zero or more ratios to
include in this Cluster.", blank=True)*
*    dvtemporal = models.ManyToManyField(DvTemporal,
related_name='%(class)s_related', help_text="Select zero or more temporal
items to include in this Cluster.", blank=True)*

*    def __str__(self):*
*        return self.prj_name.prj_name + ":" + self.cluster_subject*




Model Admin:

*class ClusterAdmin(admin.ModelAdmin):*
*    list_filter = ['prj_name__rm_version__version_id','prj_name',]*
*    search_fields = ['cluster_subject','ct_id']*
*    ordering = ['prj_name','cluster_subject']*
*    actions = [make_published, unpublish, copy_cluster]*
*    readonly_fields = ['published','schema_code','xqr_code','xqw_code',]*
*    filter_horizontal =
['dvboolean','dvuri','dvstring','dvcodedstring','dvidentifier','clusters','dvparsable','dvmedia','dvordinal','dvtemporal','dvcount','dvquantity','dvratio',]*
*    form = ClusterAdminForm*

*    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 <http://db_field.name> in
['cluster','dvboolean','dvuri','dvstring','dvcodedstring','dvidentifier','dvparsable','dvmedia',*
*
 'dvordinal','dvcount','dvquantity','dvratio','dvtemporal']:*
*            formfield.queryset =
formfield.queryset.select_related('project')*
*        return formfield*



​Each of the ManyToMany references have this in their model:


​ *   def __str__(self):*
*        return self.prj_name.prj_name + ":" + self.data_name*
*​*


​Thoughts?


--Tim​


============================================
Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3WSGNu0wOmsm3o9jr%2B7-1ASjocM18KoUV4fAtG1ZkLcAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to