mercredi 16 décembre 2015

django1.8- concatenate fields in Excel and upload in database

The read data from excel and insert into sqlite database.

The excel has two columns : "Year" and "Month". When inserting into database, I want to concatenate like below: "2013-12-31",the default date is always 31.

Here below is the snippet and reports error that "global name 'Concat' is not defined":

views.py

curs = connection.cursor()
query = """Insert into xxxx(year, month, date,...) values (%s,%s,,,,)"""
for row in range(0,sheet.nrows):
    values=[]
    global year_var
    global month_var

    for col in range(0, sheet.ncols):
        if col==0:
                year_var = sheet.cell(row, col).value
            if col==1:
                month_var = sheet.cell(row,col).value
                date= Concat(year_var,'-',month_var,'-','01')   <!--here is wrong-->
            if col==3:
                values.append(date)

            var = sheet.cell(row, col).value
            values.append(var)
        curs.execute(query, values)

Aucun commentaire:

Enregistrer un commentaire