On 9/9/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > I've added a small tutorial: > http://code.djangoproject.com/wiki/InitialSQLDataDiangoORMWay > > It describes how to use Django ORM to add initial SQL data to freshly > installed apps without files with RAW SQL > I think the steps is somewhat complex.
1) Why not use manage.py shell to run the script, though you should type more keys, but you don't need to setup the environment.(That you I suggested that manage.py should provide a *run* option, so that you can run your scripts without setup environment again. But people seem arenot interesting in it :( ) for example: $ manage.py shell >>> import install >>> install.run() 2) And the code seems tedious, we can reduce it, for example: from myghtyboard.models import Category cat_data = [ ('First Category', '0'), ('Second Category', '1'), ] cat_fields = ['cat_name', 'cat_order'] for v in cat_data: d = dict(zip(cat_fields, v)) Category.objects.create(**d) from myghtyboard.models import Forum forum_data = [ (1, 'First Forum', 'A Forum', '1'), ] forum_fields = ['forum_category', 'forum_name', 'forum_description', 'forum_order', 'forum_posts', 'forum_lastpost'] for v in forum_data: d = dict(zip(forum_fields[:len(v), v)) d['forum_category'] = Category.objects.get(id=d['forum_category']) Category.objects.create(**d) So create will auto save the new object. I don't test it. -- I like python! My Blog: http://www.donews.net/limodou UliPad Site: http://wiki.woodpecker.org.cn/moin/UliPad UliPad Maillist: http://groups.google.com/group/ulipad --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---