Its not clear how you differentiate one measure as speed or another as
dir.  Assuming only one has a link to another measure then you could
do something like:

results = Measurand.objects.exclude(entry__isnull=True).select_related
()

for speed in results:
    speed_avg = speed.avg_value
    dir_avg = speed.entry.avg_value

This first selects all measurements, excludes those that don't have a
link to another measurement, then fetches information about the
related measurements into the queryset.

-Preston



On Nov 17, 2:33 pm, tom <toab...@googlemail.com> wrote:
> Hi,
>
> i want to have the same model-field 2x in the query result.
>
> The model.py is:
> class Measurand(models.Model):
>     """
>     A Model for measurement data
>     """
>     entry = models.ForeignKey(Entry)
>     avg_value = models.FloatField(help_text='the average measurement
> value', db_index=True, blank=True, null=True)
>     def __unicode__(self):
>         return 'Measurand:' + str(self.avg_value)
>
> My raw-sql looks like:
> cursor = connection.cursor()
>         cursor.execute(""" SELECT speed.avg_value, dir.avg_value
>                        FROM data_measurand AS speed LEFT JOIN
>                        data_measurand AS dir
>                        ON speed.entry_id=dir.entry_id;
>                        """, locals() )
>         row = cursor.fetchall()
>
> How can i do this with the django-orm?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.


Reply via email to