Hi Mike, Thank heaps for direction. Appreciate your help. Cheers,
On Thu, Jun 15, 2017 at 1:52 PM, Mike Dewhirst <[email protected]> wrote: > On 15/06/2017 12:07 PM, sum abiut wrote: > >> I try to perform a division on the tuple but i am getting an error. I >> have added another column call Gl rate. i try to perform the division lin >> <td>{{a.1/a.0}}</td>but im geting an error. not sure what i am doing >> wrong here. >> >> You are asking the template to perform division. There doesn't seem to be > a "divide" filter. > > I don't know what the experts will advise but you might have to write one > yourself. https://docs.djangoproject.com/en/1.10/howto/custom-template > -tags/ > > However, I believe the accepted wisdom is that computation in the template > is more expensive than in the view. Hence I would likely do it there in > ordinary Python and pass a straight result to the template. > > That said, you might also consider https://pypi.python.org/pypi/d > jango-mathfilters > > > >> >> <table class="table table-striped"> >> <thead> >> <tr> >> <th>Net Balance</th> >> <th>Post Date</th> >> <th> GL rate</th> >> >> </thead> >> </tr> >> {%for a in results%} >> <tr> >> <td>{{a.0}}</td> >> <td>{{a.1}}</td> >> <td>{{a.1/a.0}}</td> >> </tr> >> {%endfor%} >> </table> >> >> >> >> >> On Thu, Jun 15, 2017 at 8:47 AM, sum abiut <[email protected] <mailto: >> [email protected]>> wrote: >> >> Thanks heaps. appreciate your help, pointing me to right direction. >> >> >> >> >> On Thu, Jun 15, 2017 at 5:28 AM, ludovic coues <[email protected] >> <mailto:[email protected]>> wrote: >> >> <table class="table table-striped"> >> <thead> >> <tr> >> <th>Net Balance</th> >> <th>Post Date</th> >> </thead> >> </tr> >> {%for a in results%} >> <tr> >> <td>{{a.0}}</td> >> <td>{{a.1}}</td> >> </tr> >> {%endfor%} >> </table> >> >> `{{results|pprint}}` is pretty clear. You have a list of >> tuple. Tuples have no named member so a.nat_balance return a >> None value. >> {{ a.0 }} in your django template is the equivalent of a[0] in >> python. >> >> If you want dict-like object, your problem is with SQLalchemy, >> not django >> >> 2017-06-14 5:16 GMT+02:00 sum abiut <[email protected] >> <mailto:[email protected]>>: >> >> Yes, >> on the database it spelt nat_balance >> >> >> On Wed, Jun 14, 2017 at 9:16 AM, Simon McConnell >> <[email protected] >> <mailto:[email protected]>> wrote: >> >> <td>{{a.nat_balance}}</td> >> >> sure it shouldn't be spelt >> >> <td>{{a.net_balance}}</td> >> >> ? >> >> On Wednesday, 14 June 2017 06:57:30 UTC+10, suabiut >> wrote: >> >> Hi ludovic, >> Thanks for your response. >> when i did what you say it print out the date and >> sum in an array. Date still in Julian date but i >> don't worry about the date now just want to have >> the sum display nicely in my template >> >> [(733011, 28397.54), (733030, 5136.79), (733044, >> 35.89), (733048, 0.0), (733049, 0.0), (733077, >> 6313.83), (733084, 6370.96), (733091, 150.0), >> (733104, -500.0), (733107, 0.0), (733108, 500.0), >> (733133, 5967.62), (733154, 7054.0), (733164, >> 0.0), (733174, 5698.18), (733195, 0.0), (733212, >> 5469.15), (733224, 0.0), (733255, 4887.2), >> (733265, -70000.0), (733286, 0.0), (733316, 0.0), >> (733342, -119.78999999999999), (733349, 0.0), >> (733377, 0.0), (733409, 0.0), (733422, -241.0), >> (733426, 241.0), (733440, 0.0), (733468, 0.0), >> (733498, 0.0), (733531, 0.0), (733559, 0.0), >> (733582, 104.59), (733589, 0.0), (733622, 0.0), >> (733651, 0.0), (733671, 3315.0), (733681, 0.0), >> (733713, 0.0), (733742, 0.0), (733772, -83.89), >> (733776, 0.0), (733777, 0.0), (733804, 0.0), >> (733832, 0.0), (733863, 0.0), (733895, 0.0), >> (733924, 0.0), (733948, 4.33), (733954, 0.0), >> (733986, 0.0), (734016, 0.0), (734046, 0.0), >> (734053, 0.0), (734077, 0.0), (734107, 0.0), >> (734137, -35.65), (734169, 0.0), (734197, 0.0), >> (734228, 0.0), (734260, 0.0), (734289, 0.0), >> (734319, 0.0), (734350, 0.0), (734381, 0.0), >> (734413, 0.0), (734442, 0.0), (734472, 0.0), >> (734501, -31.380000000000003), (734505, 0.0), >> (734534, 0.0), (734563, 0.0), (734595, 0.0), >> (734625, 0.0), (734655, 0.0), (734686, 0.0), >> (734716, 0.0), (734749, 0.0), (734777, 0.0), >> (734808, 0.0), (734840, 0.0), (734868, 0.0), >> (734900, 0.0), (734931, 0.0), (734960, 0.0), >> (734990, 3455.0), (735022, 1030.0), (735050, >> -2099.0), (735081, 460.0), (735113, -102.0), >> (735142, -980.0), (735173, 1538.9), (735204, >> 920.0), (735231, -500.0), (735233, 0.0), (735267, >> -1000.0), (735295, -1150.0), (735325, -250.0), >> (735355, 0.0), (735386, -560.69), (735415, 570.0), >> (735446, 0.0), (735477, -300.0), (735507, >> -205.70999999999998), (735540, 1600.0), (735569, >> -1040.0), (735598, -1404.31), (735614, 8.62), >> (735631, 0.0), (735649, 0.0), (735659, 0.0), >> (735689, 5.0), (735722, 0.0), (735750, 135.0), >> (735780, 770.0), (735813, 265.0), (735842, >> -1165.0), (735872, 30.0), (735904, -55.0), >> (735933, 4.29), (735967, 1105.0), (735968, 0.0), >> (735990, 4.32), (735995, 0.0), (736024, 0.0), >> (736055, 0.0), (736087, -1000.0), (736116, 0.0), >> (736146, 0.0), (736178, 0.0), (736208, 185.0), >> (736240, -285.68), (736269, 0.0), (736299, 0.0), >> (736332, 44.32), (736361, 0.0), (736389, 0.0), >> (736422, 0.0), (736451, -40.0), (736481, 0.0)] >> >> >> On Tue, Jun 13, 2017 at 5:33 PM, ludovic coues >> <[email protected]> wrote: >> >> Try `{{ results | pprint }}` in your template. >> >> That will not solve your problems but that >> will give you a lot more information about >> what data have been passed to your template. >> >> On 13 Jun 2017 6:53 am, "sum abiut" >> <[email protected]> wrote: >> >> Hi, >> I need some help, i am using Django as my >> web framework and sqlalchemy to query my >> database. When i pass data template its >> not showing on the template. can someone >> point me to the right direction. >> >> The post date is loaded on the template >> but the Net Balance is not loaded. Don't >> know what i am doing wrong here. >> >> below is my view.py and template >> >> >> view.py >> >> def SUMCORP(request): >> engine=create_engine('mssql+py >> mssql://username:pass@servername >> /RBVData') >> connection=engine.connect() >> metadata=MetaData() >> fund=Table('gltrxdet',metadata >> ,autoload=True,autoload_with=engine) >> stmt=select([fund.columns.date >> _posted,func.sum(fund.columns.nat_balance)]) >> stmt = >> stmt.where(fund.columns.accoun >> t_code=='002CORP') >> stmt=stmt.group_by(fund.columns.date_posted) >> results=connection.execute(stmt).fetchall() >> return >> render_to_response('fundmanage >> r_sum.html',locals()) >> >> >> template.html >> >> <table class="table table-striped"> >> <thead> >> <tr> >> >> <th>Net Balance</th> >> <th>Post Date</th> >> </thead> >> >> </tr> >> {%for a in results%} >> >> <tr> >> >> <td>{{a.nat_balance}}</td> >> <td>{{a.date_posted}}</td> >> >> </tr> >> >> {%endfor%} >> </table> >> -- 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 post to this group, send email to >> [email protected]. >> Visit this group at >> https://groups.google.com/group/django-users >> <https://groups.google.com/group/django-users >> >. >> To view this discussion on the web visit >> https://groups.google.com/d/ms >> gid/django-users/CAPCf-y7tGoLm2hxPaQpBrrm_j0VJvTF1UvE%3D- >> vQgbjh%3DzCxEMg%40mail.gmail.com >> <https://groups.google.com/d/m >> sgid/django-users/CAPCf-y7tGoLm2hxPaQpBrrm_j0VJvTF1UvE%3D- >> vQgbjh%3DzCxEMg%40mail.gmail.com?utm_medium=email&utm_source=footer>. >> For more options, visit >> https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. >> >> -- 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 post to this group, send email to >> [email protected]. >> Visit this group at >> https://groups.google.com/group/django-users >> <https://groups.google.com/group/django-users>. >> To view this discussion on the web visit >> https://groups.google.com/d/ms >> gid/django-users/CAEuG%2BTYqadry9dT8O2R0XQcivXae2OGWYaA% >> 2BoefTmO4wL22DCQ%40mail.gmail.com >> <https://groups.google.com/d/m >> sgid/django-users/CAEuG%2BTYqadry9dT8O2R0XQcivXae2OGWYaA% >> 2BoefTmO4wL22DCQ%40mail.gmail.com?utm_medium=email&utm_source=footer>. >> For more options, visit >> https://groups.google.com/d/optou >> <https://groups.google.com/d/optout> >> >> >> -- 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] >> <mailto:[email protected]>. >> To post to this group, send email to >> [email protected] >> <mailto:[email protected]>. >> Visit this group at >> https://groups.google.com/group/django-users >> <https://groups.google.com/group/django-users>. >> To view this discussion on the web visit >> https://groups.google.com/d/ms >> gid/django-users/81c3ba9f-c47d-4e85-8987-0c306f26b467%40googlegroups.com >> <https://groups.google.com/d/m >> sgid/django-users/81c3ba9f-c47d-4e85-8987-0c306f26b467%40goo >> glegroups.com?utm_medium=email&utm_source=footer>. >> >> >> For more options, visit >> https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. >> >> >> >> >> >> >> -- 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] >> <mailto:[email protected]>. >> To post to this group, send email to >> [email protected] >> <mailto:[email protected]>. >> Visit this group at >> https://groups.google.com/group/django-users >> <https://groups.google.com/group/django-users>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAPCf-y7cvSm0 >> YrGh24Fiz_N4xuCHijDxpP0r3P%3Db37XqHCuQYQ%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAPCf-y7cvSm >> 0YrGh24Fiz_N4xuCHijDxpP0r3P%3Db37XqHCuQYQ%40mail.gmail.com? >> utm_medium=email&utm_source=footer>. >> >> For more options, visit https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. >> >> >> >> >> -- >> Cordialement, Ludovic Coues >> +33 6 14 87 43 42 <tel:+33%206%2014%2087%2043%2042> >> -- 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] >> <mailto:[email protected]>. >> To post to this group, send email to >> [email protected] >> <mailto:[email protected]>. >> Visit this group at >> https://groups.google.com/group/django-users >> <https://groups.google.com/group/django-users>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAEuG%2BTYbim >> h5EKdsS9%3DDX291hLkz-hcZ27SF%3DHQstm3Uc8e1YA%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAEuG%2BTYbi >> mh5EKdsS9%3DDX291hLkz-hcZ27SF%3DHQstm3Uc8e1YA%40mail.gmail. >> com?utm_medium=email&utm_source=footer>. >> >> >> For more options, visit https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. >> >> >> >> >> >> -- >> 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] <mailto: >> [email protected]>. >> To post to this group, send email to [email protected] >> <mailto:[email protected]>. >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit https://groups.google.com/d/ms >> gid/django-users/CAPCf-y6jwX0dh1vHudHhPAhnf-amUmR%3D5uh% >> 2Bkxdsc%2BbLZrQwCg%40mail.gmail.com <https://groups.google.com/d/m >> sgid/django-users/CAPCf-y6jwX0dh1vHudHhPAhnf-amUmR%3D5uh% >> 2Bkxdsc%2BbLZrQwCg%40mail.gmail.com?utm_medium=email&utm_source=footer>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > 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 post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ms > gid/django-users/08ccbfcd-004e-53d0-8e2b-8aa3ca6be69c%40dewhirst.com.au. > > For more options, visit https://groups.google.com/d/optout. > -- 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 post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y6-8haMnZ-NyWrz2N8_2QQuETbhq32G0gSWEPEb95e99g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

