how to use django ORM in standalone script ?

200 views
Skip to first unread message

Konstantin S

unread,
Feb 23, 2009, 8:04:54 AM2/23/09
to Django users
Hello!

I need to postprocess some data in my models and the most natural way
of doing this would be to run periodically standalone script. But on
the other hand I want to use framework ORM just because it would much
more handy than raw sql. What should I import to plug in django in
standalone script that runs from command line ?

Alex Gaynor

unread,
Feb 23, 2009, 9:08:29 AM2/23/09
to django...@googlegroups.com
The best way(IMO) is to write a management script, as these will ensure all your settings stuff is set up correctly, http://docs.djangoproject.com/en/dev/howto/custom-management-commands/ has instrutions on how to do this, and you can find a few good blog posts on the ineternet.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire
"The people's good is the highest law."--Cicero

David Reynolds

unread,
Feb 23, 2009, 9:35:51 AM2/23/09
to django...@googlegroups.com
2009/2/23 Konstantin S <ktech...@gmail.com>:

I find this useful for when I need to make a standalone script:

http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/


--
David Reynolds
da...@reynoldsfamily.org.uk

Malcolm Tredinnick

unread,
Feb 23, 2009, 5:40:29 PM2/23/09
to django...@googlegroups.com

I think that post summarises most of the good options. It allows you to
use Django as a set of libraries. Alex's suggestion of writing a
management command, whilst not bad and can be useful at times, really
has the dependencies backwards when you're trying to use Django as part
of something else.

Personally, I much prefer to think of (and design) Django as a set of
libraries to built upon (and to resuse in other applications), rather
than a framework to work within.

Regards,
Malcolm

Reply all
Reply to author
Forward
0 new messages