Hello, I'm trying to use select_related() with a OneToOneField. But I'm worried about the number of queries it executes. From the django documentation: select_related(): "[...] selecting that additional related-object data when it executes its query [...]". So when I append select_related() to a object, it should make one query to my database only, at least that's how I understand it.
I'm using the following model: -------------------- models.py ------------------------- class Player(models.Model): name = models.CharField(maxlength=100, unique=True) nation = models.CharField(choices=NATION_CHOICES, maxlength=20, radio_admin=True) pub_date = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name class Admin: pass class License(models.Model): player = models.OneToOneField(Player) vid = models.IntegerField(blank=True, null=True) combat = models.IntegerField(blank=True,null=True) light = models.IntegerField(blank=True,null=True) heavy = models.IntegerField(blank=True,null=True) trade = models.IntegerField(blank=True,null=True) mining = models.IntegerField(blank=True,null=True) kplayers = models.IntegerField(blank=True,null=True) kbots = models.IntegerField(blank=True,null=True) deaths = models.IntegerField(blank=True,null=True) misingle = models.IntegerField(blank=True,null=True) migroup = models.IntegerField(blank=True,null=True) pub_date = models.DateTimeField(auto_now_add=True) def __str__(self): return "%s/%s/%s/%s/%s" % (self.combat, self.light, self.heavy, self.trade, self.mining) class Admin: pass --------------------------------------- Now I want to query the data from the Player and License model like this: >>> from django.db import connection >>> from clmdb.data.models import * >>> len(connection.queries) 0 >>> p = Player.objects.select_related() >>> x = "%s %s %s %s %s" % (p[0].license.combat, p[0].license.light, >>> p[0].license.heavy, p[0].license.trade, p[0].license.mining) >>> print x 3 6 4 7 9 >>> len(connection.queries) 10 So selecting the License model through the OneToOne key creates 10 queries. As you can imagine this adds up to 600 in larger tables... So I guess I'm not using select_related() correctly and I hope somebody can tell me how to use it so that it only makes one query. All I basically need is a JOIN. Thanks for your time. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---