That worked great for the results and profile model, but I couldn't
get it to return any data from the testcase model??

My view
def get_results(request):
        results_list = Results.objects.all().select_related
('profile','testcase')
        return render_to_response('biatf/index.html',{"results_list" :
results_list})

My template:
<form action="/graph/" method="POST">
{% if results_list %}
        <table>
  {%    for results in results_list %}
        <tr>
        <td><input type="checkbox"
name="result_id"value="{{ results.result_id }}"</td>
        <td> {{ results.date }} </td>
        <td> {{ results.profile.name }} </td>
        <td> {{ results.testcase.test_name }} </td>
        </tr>
  {% endfor %}
  </table>
        <input type="submit" value="Show Graphs"/>
{% else %}
    <p>No results are available.</p>
{% endif %}
</form>

On Feb 5, 9:41 am, felix <crucialfe...@gmail.com> wrote:
> Results.objects.all().select_related('profile','testcase')
>
> that was easy
>
> that's A join B,C
>
> if it was   A join B join C
>
> (my example)
>
> class Release
>     fk Artist
>
> class Artist
>     fk Label
>
> class Label
>
> Release.objects.all().select_related('artist','artist_label')
>
> note selecting the C class via the B class   'B_C'
>
> On Thu, Feb 5, 2009 at 5:28 PM, Daniel Roseman <
>
> roseman.dan...@googlemail.com> wrote:
>
> > On Feb 5, 3:50 pm, rc <reedcr...@gmail.com> wrote:
> > > I am newbie to Django and I am struggling to get my arms around DJango
> > > and it's data access api (models).
>
> > > I have these models:
>
> > > class Profile(models.Model):
> > >         profile_id = models.AutoField(primary_key=True)
> > >         profile_name = models.CharField(max_length=75)
> > >         def __unicode__(self):
> > >                         return self.profile_id
> > >         def __unicode__(self):
> > >                         return self.profile_name
> > >                         class Meta:
> > >                                 db_table = 'profile'
>
> > > class Testcase(models.Model):
> > >         test_id = models.AutoField(primary_key=True)
> > >         test_name = models.CharField(max_length=300)
> > >         src = models.ForeignKey(Source, null=True, blank=True)
> > >         bitrate = models.IntegerField(null=True, blank=True)
> > >         test_type = models.CharField(max_length=300)
> > >         output_resolution = models.CharField(max_length=15, blank=True)
> > >         def __unicode__(self):
> > >                 return self.test_name
> > >                 class Meta:
> > >                         db_table = 'testcase'
>
> > > class Results(models.Model):
> > >         result_id = models.AutoField(primary_key=True)
> > >         date = models.DateTimeField()
> > >         test = models.ForeignKey(Testcase)
> > >         profile = models.ForeignKey(Profile)
> > >         status = models.CharField(max_length=30)
> > >         graph = models.BlobField(null=True, blank=True)
> > >         y_psnr = models.DecimalField(null=True, max_digits=5,
> > > decimal_places=2, blank=True)
> > >         u_psnr = models.DecimalField(null=True, max_digits=5,
> > > decimal_places=2, blank=True)
> > >         v_psnr = models.DecimalField(null=True, max_digits=5,
> > > decimal_places=2, blank=True)
> > >         yuv_psnr = models.DecimalField(null=True, max_digits=5,
> > > decimal_places=2, blank=True)
> > >         def __unicode__(self):
> > >                 return self.result_id
> > >                 class Meta:
> > >                         db_table = 'results'
>
> > > and I want to be able to display this data:
>
> > > select result_id, date, profile_name, test_name, status, y_psnr,
> > > u_psnr, v_psnr, yuv_psnr
> > > from profile, testcase, results
> > > where profile.profile_id = results.profile_id
> > > and testcase.test_id = results.test_id
>
> > >  Which is very easy to do with raw sql, but struggling to do it the
> > > "django' way.
>
> > > Any ideas?
> > > I have also tried to use raw sql, but struggled to get it to work in
> > > my views and templates.
>
> > The Django ORM is there to help you. If you don't find it easy, don't
> > use it. However, the simple way of doing it would be something like
> > this:
>
> > for testcase in Testcase.objects.all():
> >    print testcase.status
> >    for result in testcase.result_set.all():
> >        print result.result_id, result.date,
> > result.profile.profile_name, \
> >                result.status, result.y_psnr, \
> >                result.u_psnr, result.v_psnr, result.yuv_psnr
>
> > You can make that much more efficient via proper use of
> > select_related, but that's the general idea.
>
> > Not related to your problem, but you've got an issue with your inner
> > Meta classes - each time they are indented under the __unicode__
> > method. They should be one indent level back.
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to