Re: Help on query
Use the aggregation way: user.report_set.annotate(count = Count('report_set')).filter(count = 1) On Sep 29, 10:39 pm, luismmontielg wrote: > yeah, something like that is what I want, but to me, that is not the > best way of doing it ... > Maybe there's a simpler way? > > thanks in advance > > On Sep 29, 8:46 am, sunn wrote: > > > This should hopefully work as well > > user_reports = user.report_set.exclude(users__id__lt = user.id, > > users_id_gt = user.id) > > > On Sep 29, 4:32 pm, sunn wrote: > > > > If you don't want to write SQL I think the easiest way is to combine > > > two querysets > > > > # You can combine queries with & and |.>>> s1 = > > > Article.objects.filter(id__exact=1) > > > >>> s2 = Article.objects.filter(id__exact=2) > > > >>> s1 | s2 > > > > [, ]>>> > > > s1 & s2 > > > > [] > > > > Fromhttp://www.djangoproject.com/documentation/models/basic/ > > > > On Sep 29, 3:58 pm, luismmontielg wrote: > > > > > that brings me all reports that have that user, but also the reports > > > > that have user and user2.. i want only the reports that have 1 user > > > > and id is equal to user.id > > > > > On Sep 29, 4:35 am, Joshua Russo wrote: > > > > > > oh ok, so just use the filter(user_id = user.id) > > > > > > On Tue, Sep 29, 2009 at 12:21 AM, luismmontielg > > > > > wrote: > > > > > > > Actually there it is, > > > > > > > users = models.ManyToManyField(User, symmetrical=True) > > > > > > > but I want to filter only the reports that contain only this user, > > > > > > or > > > > > > exclude the ones that do not have the user. > > > > > > > Thanks again > > > > > > > On 28 sep, 20:16, luismmontielg wrote: > > > > > > > sorry forgot to mention its a many to many relation so a report > > > > > > > can > > > > > > > have multiple users > > > > > > > > On Sep 28, 4:29 pm, Joshua Russo wrote: > > > > > > > > > On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg < > > > > > > luismmonti...@gmail.com>wrote: > > > > > > > > > > Hello, > > > > > > > > > I have my models like this... > > > > > > > > > > class Report(models.Model): > > > > > > > > > title = models.CharField(max_length=50, blank=True) > > > > > > > > > users = models.ManyToManyField(User, symmetrical=True) > > > > > > > > > categories = models.ManyToManyField("Category", > > > > > > > > > through='ReportDetail', \ > > > > > > > > > symmetrical=True) > > > > > > > > > > I would like to get all reports from 1 user, but that only > > > > > > > > > contain > > > > > > > > > that user > > > > > > > > > > I was looking for ne, not equals, but its removed, I cant do > > > > > > > > > it with > > > > > > > > > the exclude: > > > > > > > > > I want to make something like this > > > > > > > > > user = User.objects.get(pk=1) > > > > > > > > > user_reports = user.report_set.exclude(users__id__NOTEQUAL = > > > > > > > > > user.id > > > > > > ) > > > > > > > > > > how can I achieve this? > > > > > > > > > I'm not sure I completely follow, but user.report_set only > > > > > > > > gives you > > > > > > reports > > > > > > > > for the associated user, and it seems like that is what you > > > > > > > > want. You > > > > > > don't > > > > > > > > need any further filters or excludes. > > > > > > > > > For future reference: > > > > > > > > exclude(user_id__ne = user.id) > > > > > > > > is the same as > > > > > > > > filter(user_id = user.id) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help on query
yeah, something like that is what I want, but to me, that is not the best way of doing it ... Maybe there's a simpler way? thanks in advance On Sep 29, 8:46 am, sunn wrote: > This should hopefully work as well > user_reports = user.report_set.exclude(users__id__lt = user.id, > users_id_gt = user.id) > > On Sep 29, 4:32 pm, sunn wrote: > > > > > If you don't want to write SQL I think the easiest way is to combine > > two querysets > > > # You can combine queries with & and |.>>> s1 = > > Article.objects.filter(id__exact=1) > > >>> s2 = Article.objects.filter(id__exact=2) > > >>> s1 | s2 > > > [, ]>>> s1 > > & s2 > > > [] > > > Fromhttp://www.djangoproject.com/documentation/models/basic/ > > > On Sep 29, 3:58 pm, luismmontielg wrote: > > > > that brings me all reports that have that user, but also the reports > > > that have user and user2.. i want only the reports that have 1 user > > > and id is equal to user.id > > > > On Sep 29, 4:35 am, Joshua Russo wrote: > > > > > oh ok, so just use the filter(user_id = user.id) > > > > > On Tue, Sep 29, 2009 at 12:21 AM, luismmontielg > > > > wrote: > > > > > > Actually there it is, > > > > > > users = models.ManyToManyField(User, symmetrical=True) > > > > > > but I want to filter only the reports that contain only this user, or > > > > > exclude the ones that do not have the user. > > > > > > Thanks again > > > > > > On 28 sep, 20:16, luismmontielg wrote: > > > > > > sorry forgot to mention its a many to many relation so a report can > > > > > > have multiple users > > > > > > > On Sep 28, 4:29 pm, Joshua Russo wrote: > > > > > > > > On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg < > > > > > luismmonti...@gmail.com>wrote: > > > > > > > > > Hello, > > > > > > > > I have my models like this... > > > > > > > > > class Report(models.Model): > > > > > > > > title = models.CharField(max_length=50, blank=True) > > > > > > > > users = models.ManyToManyField(User, symmetrical=True) > > > > > > > > categories = models.ManyToManyField("Category", > > > > > > > > through='ReportDetail', \ > > > > > > > > symmetrical=True) > > > > > > > > > I would like to get all reports from 1 user, but that only > > > > > > > > contain > > > > > > > > that user > > > > > > > > > I was looking for ne, not equals, but its removed, I cant do it > > > > > > > > with > > > > > > > > the exclude: > > > > > > > > I want to make something like this > > > > > > > > user = User.objects.get(pk=1) > > > > > > > > user_reports = user.report_set.exclude(users__id__NOTEQUAL = > > > > > > > > user.id > > > > > ) > > > > > > > > > how can I achieve this? > > > > > > > > I'm not sure I completely follow, but user.report_set only gives > > > > > > > you > > > > > reports > > > > > > > for the associated user, and it seems like that is what you want. > > > > > > > You > > > > > don't > > > > > > > need any further filters or excludes. > > > > > > > > For future reference: > > > > > > > exclude(user_id__ne = user.id) > > > > > > > is the same as > > > > > > > filter(user_id = user.id) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help on query
This should hopefully work as well user_reports = user.report_set.exclude(users__id__lt = user.id, users_id_gt = user.id) On Sep 29, 4:32 pm, sunn wrote: > If you don't want to write SQL I think the easiest way is to combine > two querysets > > # You can combine queries with & and |.>>> s1 = > Article.objects.filter(id__exact=1) > >>> s2 = Article.objects.filter(id__exact=2) > >>> s1 | s2 > > [, ]>>> s1 & > s2 > > [] > > Fromhttp://www.djangoproject.com/documentation/models/basic/ > > On Sep 29, 3:58 pm, luismmontielg wrote: > > > that brings me all reports that have that user, but also the reports > > that have user and user2.. i want only the reports that have 1 user > > and id is equal to user.id > > > On Sep 29, 4:35 am, Joshua Russo wrote: > > > > oh ok, so just use the filter(user_id = user.id) > > > > On Tue, Sep 29, 2009 at 12:21 AM, luismmontielg > > > wrote: > > > > > Actually there it is, > > > > > users = models.ManyToManyField(User, symmetrical=True) > > > > > but I want to filter only the reports that contain only this user, or > > > > exclude the ones that do not have the user. > > > > > Thanks again > > > > > On 28 sep, 20:16, luismmontielg wrote: > > > > > sorry forgot to mention its a many to many relation so a report can > > > > > have multiple users > > > > > > On Sep 28, 4:29 pm, Joshua Russo wrote: > > > > > > > On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg < > > > > luismmonti...@gmail.com>wrote: > > > > > > > > Hello, > > > > > > > I have my models like this... > > > > > > > > class Report(models.Model): > > > > > > > title = models.CharField(max_length=50, blank=True) > > > > > > > users = models.ManyToManyField(User, symmetrical=True) > > > > > > > categories = models.ManyToManyField("Category", > > > > > > > through='ReportDetail', \ > > > > > > > symmetrical=True) > > > > > > > > I would like to get all reports from 1 user, but that only contain > > > > > > > that user > > > > > > > > I was looking for ne, not equals, but its removed, I cant do it > > > > > > > with > > > > > > > the exclude: > > > > > > > I want to make something like this > > > > > > > user = User.objects.get(pk=1) > > > > > > > user_reports = user.report_set.exclude(users__id__NOTEQUAL = > > > > > > > user.id > > > > ) > > > > > > > > how can I achieve this? > > > > > > > I'm not sure I completely follow, but user.report_set only gives you > > > > reports > > > > > > for the associated user, and it seems like that is what you want. > > > > > > You > > > > don't > > > > > > need any further filters or excludes. > > > > > > > For future reference: > > > > > > exclude(user_id__ne = user.id) > > > > > > is the same as > > > > > > filter(user_id = user.id) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help on query
If you don't want to write SQL I think the easiest way is to combine two querysets # You can combine queries with & and |. >>> s1 = Article.objects.filter(id__exact=1) >>> s2 = Article.objects.filter(id__exact=2) >>> s1 | s2 [, ] >>> s1 & s2 [] From http://www.djangoproject.com/documentation/models/basic/ On Sep 29, 3:58 pm, luismmontielg wrote: > that brings me all reports that have that user, but also the reports > that have user and user2.. i want only the reports that have 1 user > and id is equal to user.id > > On Sep 29, 4:35 am, Joshua Russo wrote: > > > oh ok, so just use the filter(user_id = user.id) > > > On Tue, Sep 29, 2009 at 12:21 AM, luismmontielg > > wrote: > > > > Actually there it is, > > > > users = models.ManyToManyField(User, symmetrical=True) > > > > but I want to filter only the reports that contain only this user, or > > > exclude the ones that do not have the user. > > > > Thanks again > > > > On 28 sep, 20:16, luismmontielg wrote: > > > > sorry forgot to mention its a many to many relation so a report can > > > > have multiple users > > > > > On Sep 28, 4:29 pm, Joshua Russo wrote: > > > > > > On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg < > > > luismmonti...@gmail.com>wrote: > > > > > > > Hello, > > > > > > I have my models like this... > > > > > > > class Report(models.Model): > > > > > > title = models.CharField(max_length=50, blank=True) > > > > > > users = models.ManyToManyField(User, symmetrical=True) > > > > > > categories = models.ManyToManyField("Category", > > > > > > through='ReportDetail', \ > > > > > > symmetrical=True) > > > > > > > I would like to get all reports from 1 user, but that only contain > > > > > > that user > > > > > > > I was looking for ne, not equals, but its removed, I cant do it with > > > > > > the exclude: > > > > > > I want to make something like this > > > > > > user = User.objects.get(pk=1) > > > > > > user_reports = user.report_set.exclude(users__id__NOTEQUAL = user.id > > > ) > > > > > > > how can I achieve this? > > > > > > I'm not sure I completely follow, but user.report_set only gives you > > > reports > > > > > for the associated user, and it seems like that is what you want. You > > > don't > > > > > need any further filters or excludes. > > > > > > For future reference: > > > > > exclude(user_id__ne = user.id) > > > > > is the same as > > > > > filter(user_id = user.id) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help on query
that brings me all reports that have that user, but also the reports that have user and user2.. i want only the reports that have 1 user and id is equal to user.id On Sep 29, 4:35 am, Joshua Russo wrote: > oh ok, so just use the filter(user_id = user.id) > > On Tue, Sep 29, 2009 at 12:21 AM, luismmontielg > wrote: > > > > > > > Actually there it is, > > > users = models.ManyToManyField(User, symmetrical=True) > > > but I want to filter only the reports that contain only this user, or > > exclude the ones that do not have the user. > > > Thanks again > > > On 28 sep, 20:16, luismmontielg wrote: > > > sorry forgot to mention its a many to many relation so a report can > > > have multiple users > > > > On Sep 28, 4:29 pm, Joshua Russo wrote: > > > > > On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg < > > luismmonti...@gmail.com>wrote: > > > > > > Hello, > > > > > I have my models like this... > > > > > > class Report(models.Model): > > > > > title = models.CharField(max_length=50, blank=True) > > > > > users = models.ManyToManyField(User, symmetrical=True) > > > > > categories = models.ManyToManyField("Category", > > > > > through='ReportDetail', \ > > > > > symmetrical=True) > > > > > > I would like to get all reports from 1 user, but that only contain > > > > > that user > > > > > > I was looking for ne, not equals, but its removed, I cant do it with > > > > > the exclude: > > > > > I want to make something like this > > > > > user = User.objects.get(pk=1) > > > > > user_reports = user.report_set.exclude(users__id__NOTEQUAL = user.id > > ) > > > > > > how can I achieve this? > > > > > I'm not sure I completely follow, but user.report_set only gives you > > reports > > > > for the associated user, and it seems like that is what you want. You > > don't > > > > need any further filters or excludes. > > > > > For future reference: > > > > exclude(user_id__ne = user.id) > > > > is the same as > > > > filter(user_id = user.id) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help on query
oh ok, so just use the filter(user_id = user.id) On Tue, Sep 29, 2009 at 12:21 AM, luismmontielg wrote: > > Actually there it is, > > users = models.ManyToManyField(User, symmetrical=True) > > but I want to filter only the reports that contain only this user, or > exclude the ones that do not have the user. > > Thanks again > > > On 28 sep, 20:16, luismmontielg wrote: > > sorry forgot to mention its a many to many relation so a report can > > have multiple users > > > > On Sep 28, 4:29 pm, Joshua Russo wrote: > > > > > > > > > On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg < > luismmonti...@gmail.com>wrote: > > > > > > Hello, > > > > I have my models like this... > > > > > > class Report(models.Model): > > > >title = models.CharField(max_length=50, blank=True) > > > >users = models.ManyToManyField(User, symmetrical=True) > > > >categories = models.ManyToManyField("Category", > > > > through='ReportDetail', \ > > > > symmetrical=True) > > > > > > I would like to get all reports from 1 user, but that only contain > > > > that user > > > > > > I was looking for ne, not equals, but its removed, I cant do it with > > > > the exclude: > > > > I want to make something like this > > > > user = User.objects.get(pk=1) > > > > user_reports = user.report_set.exclude(users__id__NOTEQUAL = user.id > ) > > > > > > how can I achieve this? > > > > > I'm not sure I completely follow, but user.report_set only gives you > reports > > > for the associated user, and it seems like that is what you want. You > don't > > > need any further filters or excludes. > > > > > For future reference: > > > exclude(user_id__ne = user.id) > > > is the same as > > > filter(user_id = user.id) > > > --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help on query
Actually there it is, users = models.ManyToManyField(User, symmetrical=True) but I want to filter only the reports that contain only this user, or exclude the ones that do not have the user. Thanks again On 28 sep, 20:16, luismmontielg wrote: > sorry forgot to mention its a many to many relation so a report can > have multiple users > > On Sep 28, 4:29 pm, Joshua Russo wrote: > > > > > On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg > > wrote: > > > > Hello, > > > I have my models like this... > > > > class Report(models.Model): > > > title = models.CharField(max_length=50, blank=True) > > > users = models.ManyToManyField(User, symmetrical=True) > > > categories = models.ManyToManyField("Category", > > > through='ReportDetail', \ > > > symmetrical=True) > > > > I would like to get all reports from 1 user, but that only contain > > > that user > > > > I was looking for ne, not equals, but its removed, I cant do it with > > > the exclude: > > > I want to make something like this > > > user = User.objects.get(pk=1) > > > user_reports = user.report_set.exclude(users__id__NOTEQUAL = user.id) > > > > how can I achieve this? > > > I'm not sure I completely follow, but user.report_set only gives you reports > > for the associated user, and it seems like that is what you want. You don't > > need any further filters or excludes. > > > For future reference: > > exclude(user_id__ne = user.id) > > is the same as > > filter(user_id = user.id) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help on query
sorry forgot to mention its a many to many relation so a report can have multiple users On Sep 28, 4:29 pm, Joshua Russo wrote: > On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg wrote: > > > > > > > > > Hello, > > I have my models like this... > > > class Report(models.Model): > > title = models.CharField(max_length=50, blank=True) > > users = models.ManyToManyField(User, symmetrical=True) > > categories = models.ManyToManyField("Category", > > through='ReportDetail', \ > > symmetrical=True) > > > I would like to get all reports from 1 user, but that only contain > > that user > > > I was looking for ne, not equals, but its removed, I cant do it with > > the exclude: > > I want to make something like this > > user = User.objects.get(pk=1) > > user_reports = user.report_set.exclude(users__id__NOTEQUAL = user.id) > > > how can I achieve this? > > I'm not sure I completely follow, but user.report_set only gives you reports > for the associated user, and it seems like that is what you want. You don't > need any further filters or excludes. > > For future reference: > exclude(user_id__ne = user.id) > is the same as > filter(user_id = user.id) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help on query
On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg wrote: > > Hello, > I have my models like this... > > class Report(models.Model): >title = models.CharField(max_length=50, blank=True) >users = models.ManyToManyField(User, symmetrical=True) >categories = models.ManyToManyField("Category", > through='ReportDetail', \ > symmetrical=True) > > > I would like to get all reports from 1 user, but that only contain > that user > > I was looking for ne, not equals, but its removed, I cant do it with > the exclude: > I want to make something like this > user = User.objects.get(pk=1) > user_reports = user.report_set.exclude(users__id__NOTEQUAL = user.id) > > how can I achieve this? > I'm not sure I completely follow, but user.report_set only gives you reports for the associated user, and it seems like that is what you want. You don't need any further filters or excludes. For future reference: exclude(user_id__ne = user.id) is the same as filter(user_id = user.id) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Help on query
Hello, I have my models like this... class Report(models.Model): title = models.CharField(max_length=50, blank=True) users = models.ManyToManyField(User, symmetrical=True) categories = models.ManyToManyField("Category", through='ReportDetail', \ symmetrical=True) I would like to get all reports from 1 user, but that only contain that user I was looking for ne, not equals, but its removed, I cant do it with the exclude: I want to make something like this user = User.objects.get(pk=1) user_reports = user.report_set.exclude(users__id__NOTEQUAL = user.id) how can I achieve this? Thanks in advance Luis Montiel --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help on query
On May 19, 12:11 pm, Lokesh wrote: > class Users(models.Model): > userId = models.IntegerField(max_length=2, primary_key=True) > userName = models.CharField(max_length=10, null=False, > blank=False) > > def __unicode__(self): > return self.userName > > class MotherTongue(models.Model): > MT_id = models.IntegerField(max_length=2, null=False, blank=False, > unique=True) > MT_value = models.CharField(max_length=15, null=False, > blank=False) > > def __unicode__(self): > return self.MT_value > > class Sr_Pr_MotherTongue(models.Model): > Sr_Pr_userId = models.ForeignKey(Users, to_field='userId') > Sr_Pr_MT_id = models.ForeignKey(MotherTongue, to_field='MT_id') > Sr_Pr_type = models.CharField(max_length=7, null=False, > blank=False) > > def __unicode__(self): > return self.Sr_Pr_type > > mysql> select * from polls_users; > ++--+ > | userId | userName | > ++--+ > | 1 | django3 | > | 2 | django2 | > | 3 | django1 | > ++--+ > mysql> select * from polls_mothertongue; > ++---+--+ > | id | MT_id | MT_value | > ++---+--+ > | 1 | 1 | Telugu | > | 2 | 2 | English | > | 3 | 3 | Hindi | > | 4 | 4 | Sindi | > ++---+--+ > mysql> select * from polls_sr_pr_mothertongue; > ++-+++ > | id | Sr_Pr_userId_id | Sr_Pr_MT_id_id | Sr_Pr_type | > ++-+++ > | 2 | 1 | 1 | search | > | 3 | 2 | 2 | pref | > | 4 | 3 | 4 | search | > ++-+++ > > mysql>select a.mt_value, b.Sr_Pr_type, c.userName from > polls_mothertongue a, polls_sr_pr_mothertongue b, polls_users c where > a.mt_id = b.sr_pr_mt_id_id and c.userId=1 and > c.userId=b.Sr_Pr_userId_id; > Django -> ?? > step1 - p = Users.objects.get(pk=1) => get the user id object > step2 - not able to proceed further > +--++--+ > | mt_value | Sr_Pr_type | userName | > +--++--+ > | Telugu | search | django3 | > +--++--+ > > Could some one please guide me how I can achieve the above mysql > result from django query > > Regards, > Lokesh Posting a bunch of badly-formatted SQL is not at all helpful. What do you actually want to achieve? If you can spell it out in plain language - ie 'I want all the users where...' - then it might be more obvious how to do it in Django. -- DR. --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Help on query
class Users(models.Model): userId = models.IntegerField(max_length=2, primary_key=True) userName = models.CharField(max_length=10, null=False, blank=False) def __unicode__(self): return self.userName class MotherTongue(models.Model): MT_id = models.IntegerField(max_length=2, null=False, blank=False, unique=True) MT_value = models.CharField(max_length=15, null=False, blank=False) def __unicode__(self): return self.MT_value class Sr_Pr_MotherTongue(models.Model): Sr_Pr_userId = models.ForeignKey(Users, to_field='userId') Sr_Pr_MT_id = models.ForeignKey(MotherTongue, to_field='MT_id') Sr_Pr_type = models.CharField(max_length=7, null=False, blank=False) def __unicode__(self): return self.Sr_Pr_type mysql> select * from polls_users; ++--+ | userId | userName | ++--+ | 1 | django3 | | 2 | django2 | | 3 | django1 | ++--+ mysql> select * from polls_mothertongue; ++---+--+ | id | MT_id | MT_value | ++---+--+ | 1 | 1 | Telugu | | 2 | 2 | English | | 3 | 3 | Hindi| | 4 | 4 | Sindi| ++---+--+ mysql> select * from polls_sr_pr_mothertongue; ++-+++ | id | Sr_Pr_userId_id | Sr_Pr_MT_id_id | Sr_Pr_type | ++-+++ | 2 | 1 | 1 | search | | 3 | 2 | 2 | pref | | 4 | 3 | 4 | search | ++-+++ mysql>select a.mt_value, b.Sr_Pr_type, c.userName from polls_mothertongue a, polls_sr_pr_mothertongue b, polls_users c where a.mt_id = b.sr_pr_mt_id_id and c.userId=1 and c.userId=b.Sr_Pr_userId_id; Django -> ?? step1 - p = Users.objects.get(pk=1) => get the user id object step2 - not able to proceed further +--++--+ | mt_value | Sr_Pr_type | userName | +--++--+ | Telugu | search | django3 | +--++--+ Could some one please guide me how I can achieve the above mysql result from django query Regards, Lokesh --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---