Hello,

I am trying to perform a complex math calculation from a django query set. 
How can I pass the results to the template for display? Annotations won't 
work since the math is not a simple sum, diff or average. 

MODEL

class TncData(models.Model):
    callsign = models.TextField(max_length=20)
    lat = models.FloatField(null=True, blank=True, default=None)
    lon = models.FloatField(null=True, blank=True, default=None)
    path = models.TextField(max_length=250)
    message = models.TextField(max_length=250)
    dt_heard = models.DateTimeField(auto_now_add=False)

    def __str__(self):
        return str(self.callsign)

VIEW

def position_view(request):

    packet_data = TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]

    *# my complex math calculation*
*     # need to do something like append distance to packet_data like 
packet_data.distance*

*    distance = "# complex math formula using packet_data.lat and 
packet_data.lon"*

    return render(request, 'main/position.html', 
{'packet_data':packet_data,})

TEMPLATE

{% for field in packet_data %}

    <tr class='atable'>
    <td class='atable'>{{field.callsign}}</td>
    <td class='atable'>{{field.lat|floatformat:2}} N 
{{field.lon|floatformat:2}} W </td>
    <td class='atable'></td>
    *<td class='atable'>{{packet_data.distance}}</td>*
    <td class='atable'>{{field.dt_heard|date:"D m/d H:i"}}</td>
    </tr>

{% endfor %}
                         

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/49f44d93-e011-4d00-a022-3eb064dfac86n%40googlegroups.com.

Reply via email to