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

Тел: +7 965 3737 888





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>How to use:
python manage.py makefixture
<p>will display what models are installed
python manage.py makefixture User[:3]
python manage.py makefixture auth.User[:3]
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.
python manage.py makefixture YourModel[3] YourModel[6:10]
<p>will serialize YourModel with key 3 and keys 6 to 9 inclusively.
<p>Of course, you can serialize whole tables, and also different tables at once, and use options of dumpdata:
python manage.py makefixture --format=xml --indent=4 YourModel[3] AnotherModel auth.User[:5] auth.Group

Вопрос полезен? Да0/Нет0

Ответы (4):

Ответ полезен? Да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.

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

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


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

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

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

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