KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Its day two of my new life with Django, please excuse the simplicity of my question. I have an existing DB table(read-only access) that I have successfully displayed the contents of on a webpage using urls, views, models and all that good stuff. The challenge I have is the table does not contain all the information I need to display. The table contains test results with the columns, sampletime, samplevalue, sampleresult. I need to display different data based on what I calculate from those columns. My end goal is to display this info as a time series graph using flotr . For now Id be happy to just dump the data I need to a table on a web page.(So I can visualize the resulting data) What Id like to pass to the template is, jssampletime(the sampletime datetime object converted to javascript epoch ms) resultvalue(rolling sum+- of samplevalue based on whether sampleresult was good or bad) I'm fine with creating jssampletime and resultvalue using def functions. I presume I would add these functions to views.py I guess what I need to do iterate over the a querySet in views.py and store the results in a list of dictionaries which I pass to the template. Something like this(code not tested). views.py # views.py # Sudo code to assit in asking the question from django.shortcuts import render_to_response from thing.reporter.models import Samples def _datetime_to_js(sampletime): #.. date conversion epoch magic return jsd_result def _rolling_sum(samplevalue,sampleresult): #.. summing magic return sum_result def dumptable(request): # The def that is called by urls.py object_list = Samples.objects.all() list_for_template = [] for row in object_list: jssampletime = _datetime_to_js(row.sampletime) resultvalue = _rolling_sum(row.samplevalue,row.sampleresult) list
Tags (comma-separated)
Save Edits
Cancel