On May 19, 12:11 pm, Lokesh <lokeshmarema...@gmail.com> 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 -~----------~----~----~----~------~----~------~--~---