Re: Need help writing join Django query for this simple model..

2011-08-09 Thread Shawn Milochik
This is where using the related_name kwarg comes in. You can also use the default value, which in this case is academics_set. I see you made most of the recommended changes to your model definitions. I'd just like to reiterate two: Remove the underscore in your model name. Remove the 's

RE: Need help writing join Django query for this simple model..

2011-08-09 Thread Hayyan Rafiq
last): File "", line 1, in AttributeError: 'int' object has no attribute 'gpa' My question is how can i make it work both ways ?? Is that even possible??? Date: Tue, 9 Aug 2011 08:50:48 -0400 Subject: Re: Need help writing join Django query for this simple model

RE: Need help writing join Django query for this simple model..

2011-08-09 Thread Hayyan Rafiq
rt Student_Info >>> list=Student_Info.objects.all() >>> obj=list[0] >>> obj Now i got the Student_info object. and i know Student_Info is linked to Academics via Roll_No.. so now how could i read the GPA in Academics any suggestions?? Date: Tue, 9 Aug 2011 08:50:48 -0400 S

Re: Need help writing join Django query for this simple model..

2011-08-09 Thread Karen Tracey
On Mon, Aug 8, 2011 at 11:49 PM, Hayyan Rafiq wrote: > so i tried this now > > > class Student_Info(models.Model): > Roll_No = models.IntegerField(primary_key=True) > Cell_No = models.IntegerField() > > E_mail = models.EmailField(max_length=30) > > class Academics(models.Model): > * #Roll

RE: Need help writing join Django query for this simple model..

2011-08-08 Thread Hayyan Rafiq
in AttributeError: 'Academics' object has no attribute 'Student_Info' Any ideas or suggestions?? Date: Mon, 8 Aug 2011 23:07:59 -0400 From: sh...@milochik.com To: django-users@googlegroups.com Subject: Re: Need help writing join Django query for this simple model..

RE: Need help writing join Django query for this simple model..

2011-08-08 Thread Hayyan Rafiq
Re: Need help writing join Django query for this simple model.. Make your life a little easier and add a related_name argument to your Roll_No foreign key. Example: Roll_No = models.ForeignKey('Student_Info',to_field='Roll

Re: Need help writing join Django query for this simple model..

2011-08-08 Thread Shawn Milochik
Make your life a little easier and add a related_name argument to your Roll_No foreign key. Example: Roll_No = models.ForeignKey('Student_Info',to_field='Roll_No', related_name = 'students') Then: obj.students.all()[0].E_mail Without a related name: obj.student_set.all()[0].E_mail No

RE: Need help writing join Django query for this simple model..

2011-08-08 Thread Hayyan Rafiq
ochik.com To: django-users@googlegroups.com Subject: Re: Need help writing join Django query for this simple model.. On 08/08/2011 10:55 PM, Hayyan Rafiq wrote: Tried that >>> recs=Academics.objects.all() >>> recs[0

Re: Need help writing join Django query for this simple model..

2011-08-08 Thread Shawn Milochik
On 08/08/2011 10:55 PM, Hayyan Rafiq wrote: Tried that >>> recs=Academics.objects.all() >>> recs[0] >>> obj=recs[0] >>> obj.Cell_No Traceback (most recent call last): File "", line 1, in AttributeError: 'Academics' object has no attribute 'Cell_No' Am i missing something?? Yes, 'Cell_No'

RE: Need help writing join Django query for this simple model..

2011-08-08 Thread Hayyan Rafiq
ng something?? > Date: Mon, 8 Aug 2011 22:48:05 -0400 > From: sh...@milochik.com > To: django-users@googlegroups.com > Subject: Re: Need help writing join Django query for this simple model.. > > It would just be: > > recs = Academics.objects.all() > > Because

Re: Need help writing join Django query for this simple model..

2011-08-08 Thread Shawn Milochik
It would just be: recs = Academics.objects.all() Because that table has all those fields. Also, some style notes: It's non-standard to put underscores in class names. It's non-standard to put capital letters in field names. It's non-standard (and grammatically incorrect) to name

Need help writing join Django query for this simple model..

2011-08-08 Thread Hayyan Rafiq
Suppose I have the following 2 Classes in models. class Student_Info(models.Model): Roll_No = models.IntegerField(primary_key=True) E_mail = models.EmailField(max_length=30) class Academics(models.Model): Roll_No = models.ForeignKey('Student_Info',to_field='Roll_No') GPA = models.Inte