7 views
Skip to first unread message

sum abiut

unread,
Jun 26, 2017, 8:01:26 PM6/26/17
to django...@googlegroups.com
Hi all,
I have this function where i i use mssqlalchmy to to fetch data from a mssql database. I am fetching data from a column but what i am interested in, is just to get a data from last field/row on that column.

is there are way to get that done from template?. this what i have done from the template.html but i am getting an error : could not parse the remainder '[-1]'



template.html

<table class="table table-striped">
  <thead>
<tr>
 
  <th> GL Rate</th>

</thead>

</tr>
{%for a in results%}

<tr>

  <td>{{a.buy_rate[-1]}}</td>

  </tr>

{%endfor%}
</table>


view.py
def rate(request):
    engine=create_engine('mssql+pymssql://username:passwprd@localhost /database')
    connection=engine.connect()
    metadata=MetaData()
    funds=Table('mccurtdt',metadata,autoload=True,autoload_with=engine)
   
    stmt=select([funds.columns.buy_rate])
    stmt=stmt.where(and_(funds.columns.rate_type=='MID',funds.columns.from_currency=='AUD',))
    results=connection.execute(stmt).fetchall()
    return render_to_response('rate.html',locals())

Mike Dewhirst

unread,
Jun 26, 2017, 10:11:49 PM6/26/17
to django...@googlegroups.com, sum abiut
On 27/06/2017 10:00 AM, sum abiut wrote:
> Hi all,
> I have this function where i i use mssqlalchmy to to fetch data from a
> mssql database. I am fetching data from a column but what i am
> interested in, is just to get a data from last field/row on that column.
>
> is there are way to get that done from template?. this what i have
> done from the template.html but i am getting an error : could not
> parse the remainder '[-1]'
>
>
>
> template.html
>
> <table class="table table-striped">
> <thead>
> <tr>
>
> <th> GL Rate</th>
>
> </thead>
>
> </tr>
> {%for a in results%}
>
> <tr>
>
> <td>{{a.buy_rate[-1]}}</td>


<td>{{ a.buy_rate | last }}</td>

https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#last


>
> </tr>
>
> {%endfor%}
> </table>
>
>
> view.py
> def rate(request):
> engine=create_engine('mssql+pymssql://username:passwprd@localhost
> /database')
> connection=engine.connect()
> metadata=MetaData()
> funds=Table('mccurtdt',metadata,autoload=True,autoload_with=engine)
>
> stmt=select([funds.columns.buy_rate])
> stmt=stmt.where(and_(funds.columns.rate_type=='MID',funds.columns.from_currency=='AUD',))
> results=connection.execute(stmt).fetchall()
> return render_to_response('rate.html',locals())
>
> --
> 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 django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> 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-y5EMP6qx59zzfQ-xx-7kz2QbUO%2Bq23pPvJdXTb0B9fdqw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPCf-y5EMP6qx59zzfQ-xx-7kz2QbUO%2Bq23pPvJdXTb0B9fdqw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages