Hi,
I been trying to create a backward relation using queryset and the joining
is working fine, accept that its not including the other joined table in the
selected columns. Below is my models, queryset and query.__str__() print
class Main(models.Model):
slug = models.SlugField()
is_active = models.BooleanField(default=True)
site = models.ForeignKey(Site)
parent = models.ForeignKey('self', blank=True, null=True,
limit_choices_to={'parent' : None})
class Meta:
unique_together = (("slug", "parent"))
def __unicode__(self):
return self.slug
class MainI18n(models.Model):
main = models.ForeignKey(Main)
language = models.CharField(max_length=2,
choices=settings.LANGUAGES)
title = models.CharField(max_length=100)
label = models.CharField(max_length=200, blank=True,
null=True)
description = models.TextField(blank=True, null=True)
disclaimer = models.TextField(blank=True, null=True)
class Meta:
unique_together = (("language", "main"))
def __unicode__(self):
return self.title
class List(models.Model):
main = models.ForeignKey(Main)
slug = models.SlugField(unique=True)
is_active = models.BooleanField(default=True)
parent = models.ForeignKey('self', blank=True, null=True)
def __unicode__(self):
return self.slug
class ListI18n(models.Model):
list = models.ForeignKey(List)
language = models.CharField(max_length=2,
choices=settings.LANGUAGES)
title = models.CharField(max_length=50)
description = models.TextField()
class Meta:
unique_together = (("language", "list"))
def __unicode__(self):
return self.title
and my queryset is
Main.objects.select_related('main',
'parent').filter(list__is_active=True, maini18n__language='en',
list__listi18n__language='en')
and this is what my query is printing
'SELECT `category_main`.`id`, `category_main`.`slug`,
`category_main`.`is_active`, `category_main`.`site_id`,
`category_main`.`parent_id`, T5.`id`, T5.`slug`, T5.`is_active`,
T5.`site_id`, T5.`parent_id` FROM `category_main` INNER JOIN
`category_maini18n` ON (`category_main`.`id` =
`category_maini18n`.`main_id`) INNER JOIN `category_list` ON
(`category_main`.`id` = `category_list`.`main_id`) INNER JOIN
`category_listi18n` ON (`category_list`.`id` =
`category_listi18n`.`list_id`) LEFT OUTER JOIN `category_main` T5 ON
(`category_main`.`parent_id` = T5.`id`) WHERE
(`category_maini18n`.`language` = en AND `category_list`.`is_active` = True
AND `category_listi18n`.`language` = en )'
anyone can help show columns from list and listi18n? I tried extra but It
doesn't allow me to pass things like category_list.*
thanks
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.