Задать вопрос

Тел: +7 965 3737 888

555

Просмотров

8

Ответов

Command to dump data as a python script

<p>This creates a fixture in the form of a python script.</p>
<p>Handles:</p>
<ol><li>ForeignKey and ManyToManyFields (using python variables, not IDs)</li>
<li>Self-referencing ForeignKey (and M2M) fields</li>
<li>Sub-classed models</li>
<li>ContentType fields</li>
<li>Recursive references</li>
<li>AutoFields are excluded</li>
<li>Parent models are only included when no other child model links to it</li>
</ol><p>There are a few benefits to this:</p>
<ol><li>edit script to create 1,000s of generated entries using for loops, python modules etc.</li>
<li>little drama with model evolution: foreign keys handled naturally without IDs, new and removed columns are ignored</li>
</ol><p>The <a href="http://code.djangoproject.com/ticket/6243">runscript command by poelzi</a>, complements this command very nicely! e.g.</p>
$ ./manage.py dumpscript appname &gt; scripts/testdata.py
$ ./manage.py reset appname
$ ./manage.py runscript testdata

Вопрос полезен? Да0/Нет0
file_3883.py(17.0Кб)
None

Ответы (8):

Ответjohnboxall:27.02.2009
Ответ полезен? Да0/Нет0

Awesome but don't try this one with more than a handful of records unless you've got something beefy!

Ответtjurewicz:30.07.2008
Ответ полезен? Да0/Нет0

I'm relatively new to Django and am trying to get this script to work. Can somebody point me in a direction to running these types of scripts?

Thanks, Trent

Ответaj:17.07.2008
Ответ полезен? Да0/Нет0

Great script Will - thanks.

I found (and fixed) a bug against the latest trunk and have added model include and exclude options on the command line. Would you like a copy so you can choose whether to update your snippet and perhaps point out where what I've done screws everything up? ;) If so I'm on aj 'at' cubbyhole 'dot' net.

AJ

Ответwillhardy:01.07.2008
Ответ полезен? Да0/Нет0

object and model cherry-picking?

./manage.py dumpscript | grep "appname_modelname_"

But please no bug reports on this one :-P

Ответburiy:26.06.2008
Ответ полезен? Да0/Нет0

nice one. how about object and model cherry-picking? ;)

Ответgorans:25.06.2008
Ответ полезен? Да0/Нет0

Nice one Will!

Ответtrbs:24.06.2008
Ответ полезен? Да0/Нет0

dumpscript is now part of django-command-extensions :)

Ответjokull:24.06.2008
Ответ полезен? Да0/Нет0

+1 for ./manage.py dumpdata --format python