Malcolm, I believe that should be params = dict(zip(fields, row))

On Nov 28, 8:34 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2008-11-28 at 19:54 +0900, Russell Keith-Magee wrote:
>
> [...]
>
> > >>> cursor.execute('SELECT ...')
> > >>> row = cursor.fetchone()
> > >>> a = Author(*row)
>
> > At this point, a will be a fully populated Author instance,
> > indistinguishable from one retrieved using a queryset.
>
> > The caveat on this technique is that the SELECT you execute using the
> > cursor to obtain the row must contain all the columns in your model,
> > specified in the same order that your model defines them. This
> > includes the auto-added id column, if appropriate. If you're uncertain
> > which fields will be required, and in what order, Author._meta.fields
> > contains the list that Django will expect.
>
> If you only have a subset of the fields, or if they aren't in the
> expected order, you can also supply the values as keyword argument
> parameters to the model initialisation function. Zip up the values with
> the names of the parameters they represent and pass that in:
>
>         fields = ('name', 'age', 'data')
>         results = []
>         for row in cursor.fetchall():
>            params = zip(fields, row)
>            results.append(Author(**params)
>
> Regards,
> Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to