Stored Procedure result to Django Model -


if have model like:

class person(models.model):     id = models.integerfield()     first_name = models.charfield(max_length=50)     last_name = models.integerfield()     birthday = models.datefield()     address = models.charfield(max_length=250)          phone = models.timefield() 

to create person class objects data stored procedure, like:

cursor = connection.cursor() cursor.callproc('sp_get_person_by_id', {id:1234}) results = cursor.fetchall()  [person(*row) row in results] 

but "sp_get_person_by_id" returns more fields person class attributes. therefore "shit happens", error happens because there fields don't have attributes map.

it's possible map attributes? how can that?

thx in advance.

cheers.

if know order of attributes you're getting stored procedure can pass them model this:

cursor = connection.cursor() cursor.callproc('sp_get_person_by_id', {id:1234}) results = cursor.fetchall() result_list = []     row in results:     p = self.model(id=row[0], fist_name=row[1], last_name=row[2], birthday=row[3])     result_list.append(p) return result_list 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

java - How to create Table using Apache PDFBox -

c# - Attempting to upload to FTP: System.Net.WebException: System error -