I have a function that query the db and extract and display data on a
template


def bydate_display(request):
    if "selectdate" in request.POST and "selectdate1" in request.POST and
"selectaccount" in request.POST:
        selected_date = request.POST["selectdate"]
        selected_date1 = request.POST["selectdate1"]
        selected_acc = request.POST["selectaccount"]
        if selected_date==selected_date and selected_date1==selected_date1
and selected_acc==selected_acc:
            convert=datetime.datetime.strptime(selected_date,
"%Y-%m-%d").toordinal()
            convert1=datetime.datetime.strptime(selected_date1,
"%Y-%m-%d").toordinal()
            engine=create_engine('mssql+pymssql://username:password@serve
/db')
            connection=engine.connect()
            metadata=MetaData()

fund=Table('gltrxdet',metadata,autoload=True,autoload_with=engine)

rate=Table('gltrx_all',metadata,autoload=True,autoload_with=engine)


stmt=select([fund.columns.account_code,fund.columns.description,fund.columns.nat_balance,fund.columns.rate_type_home,rate.columns.date_applied,rate.columns.date_entered,fund.columns.journal_ctrl_num,rate.columns.journal_ctrl_num])

stmt=stmt.where(and_(rate.columns.journal_ctrl_num==fund.columns.journal_ctrl_num,fund.columns.account_code==selected_acc,rate.columns.date_applied.between(convert,convert1)))
            results=connection.execute(stmt).fetchall()


            return render(request,'bydatedisplay.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 [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-y6M4FmAp8m2PKULcP0ZFWTY%3Ddbe0NAf0u6ffbFm04KYMg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to