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

Тел: +7 965 3737 888

620

Просмотров

4

Ответов

Command to make fixtures.

<p>"Make fixture" command. Highly useful for making test fixtures.
   Use it to pick only few items from your data to serialize, restricted by primary keys.
   By default command also serializes foreign keys and m2m relations.
   You can turn off related items serialization with --skip-related option.
</p>
<p>How to use:
</p>
python manage.py makefixture
<p>will display what models are installed
</p>
python manage.py makefixture User[:3]
<p>or 
</p>
python manage.py makefixture auth.User[:3]
<p>or
</p>
python manage.py makefixture django.contrib.auth.User[:3]
<p>will serialize users with ids 1 and 2, with assigned groups, permissions and content types.
</p>
python manage.py makefixture YourModel[3] YourModel[6:10]
<p>will serialize YourModel with key 3 and keys 6 to 9 inclusively.
</p>
<p>Of course, you can serialize whole tables, and also different tables at once, and use options of dumpdata:
</p>
python manage.py makefixture --format=xml --indent=4 YourModel[3] AnotherModel auth.User[:5] auth.Group

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

Ответы (4):

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

Useful. Could use a little refactoring and debugging.

Not sure if this matters, but slice is now a native part of the python language; so %s/\<slice>/model_slice/g for starters, (i.e. replace slice with model_slice, if you're not familiar with vim.)

Then insert around line 108 model_slice = model_slice if model_slice != '' else ['',''] after the other processing on model_slice has been done.

That's just a quick hack fix to the requirement for a slice.

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

Doesn't work unless you specify a slice. I had to use

myapp.MyModel[:]

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

Doesn't seem to work with inherited models. Insanely useful, though.

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

This would be a cool candidate for django-command-extensions.