--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/58f721ad-2ee4-4016-ac6f-b48661c4ce5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from django.db import models
class Foo(models.Model):
pass
class Bar(models.Model):
foo = models.ForeignKey(Foo)
def __str__(self):
return "Foo %s" % self.foo
class Baz(models.Model):
bars = models.ManyToManyField(Bar)
from django.contrib import admin
class BazAdmin(admin.ModelAdmin):
def formfield_for_many_to_many(self, db_field, *args, **kwargs):
formfield = super(BazAdmin, self).formfield_for_many_to_many(db_field, *args, **kwargs)
if db_field.name == 'baz':
formfield.queryset = formfield.queryset.select_related('foo')
return formfield
if db_field.name == 'baz':
if db_field.name == 'bars':
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b769eae9-7b78-43e8-bfaa-eae864bcd386%40googlegroups.com.
> 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?
Erik
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/D28F7970-28EB-46DE-9FD2-3BD3F63A085E%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.
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.
Erik
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/ED7D33CB-EE4B-451D-B00F-7B24BFAD7A90%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.