Wednesday, December 23, 2015

Re: django cursor fetchall change datetime.datetime and decimal stamp

I got it to work ..

def dictfetchall(cursor):
"Returns all rows from a cursor as a dict"
fieldnames = [name[0] for name in cursor.description]
result = []
for row in cursor.fetchall():
rowset = []
for field in zip(fieldnames, row):
L=list(field)
if (isinstance(field[1], datetime.datetime)):
L[1]=L[1].strftime("%Y-%m-%d %H:%M:%S")
print (L[1])
if (isinstance(field[1], decimal.Decimal)):
L[1]=str(L[1])
rowset.append(L)
result.append(dict(rowset))
return result 

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/58f8de27-9dc0-4c23-8d74-0b0539ea2c95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment