On 9/17/07, Julio César Carrascal Urquijo <[EMAIL PROTECTED]> wrote:
>
> def import_from_file(filename):
>     ...
>     for r in product_records(file):
>         p = Product()
>         p.code = r['code']
>         p.parent = Product.get(code = r['parent_code'])
>         ...
>         p.save()
>         for category in r['category_codes']:
>             c = Category.get(code = category)
>             c.posts.add(p)

This will be slow because each call to c.posts.add() will be a
separate insert. This can be significantly sped up if you do all the
adds in one hit:

c.posts = [... list of post objects (or ids of post objects) ...]

This assignment will be performed as a single SQL insert, very similar
to the one you describe.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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