I have the following models (Well, very simplified): class Category(models.Model): code = models.CharField(maxlength=200, unique=True) posts = models.ManyToManyField('Post')
class Product(models.Model): parent = models.ForeignKey('Post') code = models.CharField(maxlength=200, unique=True) Now, I have a large file with products that I need to import and each record has a list of categories that need to be associated with the product: 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 sort of works but it is too inefficient to import all products. What I really like to do is something along the lines of: cursor.execute("""insert into store_product (code, parent_id, ...) select %s, id as parent_id, ... from store_product where code = %s""", r['code'] r['parent_code']) and cursor.execute("""insert into store_category_products (product_id, category_id) select %s, id as category_id, ... from store_category where code in (%s)""", p.id, r['category_codes']) Is possible to express this within the django db-api or should I just give up and use raw cursors? Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---