djangosnippets.org: Latest snippets tagged with 'fixtures'https://djangosnippets.org/tags/fixtures/2016-09-08T09:14:44.151728-05:00utf8-friendly dumpdata management command (no escape symbols) #4
2016-09-08T09:14:44.151728-05:00muciushttps://djangosnippets.org/snippets/10587/<p>The version of snippet that works with Django 1.9</p>
Freely redistributableutf8-friendly dumpdata management command for yaml (no escape symbols) #2
2016-09-08T09:09:16.423595-05:00muciushttps://djangosnippets.org/snippets/10586/<p>This is a revised version of https://djangosnippets.org/snippets/2921/</p>
Freely redistributableMake fixtures and follow relationships.
2015-07-01T12:21:22.652250-05:00andybakhttps://djangosnippets.org/snippets/10506/<p>Inspired and based on https://djangosnippets.org/snippets/918/</p>
<p>Improvements:</p>
<ul>
<li>Supports natural keys</li>
<li>Uses Django's Collector so hopefully follows reverse relationships</li>
<li>Fixes problem when you don't specify a slice</li>
<li>PEP8 etc.</li>
</ul>
Freely redistributableutf8-friendly dumpdata management command for yaml (no escape symbols)
2013-05-17T22:50:44.148805-05:00muciushttps://djangosnippets.org/snippets/2921/<p>This is a YAML version of http://djangosnippets.org/snipptes/2397</p>
Freely redistributableutf8-friendly dumpdata management command (no escape symbols) #3
2013-05-05T12:36:38.052197-05:00inductorhttps://djangosnippets.org/snippets/2916/<p>The version of <a href="http://djangosnippets.org/snippets/2397/">snippet</a> that works with Django 1.5. Kudos to <a href="http://djangosnippets.org/users/kmike/">kmike</a> for the original snippet.</p>
Freely redistributableProper fixtures loading in south data migrations
2013-02-27T03:08:27.346020-06:00JustDelighthttps://djangosnippets.org/snippets/2897/<p>South documentation <a href="http://south.readthedocs.org/en/0.7.6/fixtures.html#fixtures-from-migrations">contains a description</a> of the way you can load fixtures inside the data-migrations.</p>
<p>def forwards(self, orm):
from django.core.management import call_command
call_command("loaddata", "my_fixture.json")</p>
<p>It seems pretty clear and easy, but in fact it does not work the way you expect from south migrations, because the fixture loading does not …</p>
Freely redistributableMongoDB data load
2013-01-03T09:37:14.144420-06:00jose_lpahttps://djangosnippets.org/snippets/2873/<p>This snippet loads data from JSON files into a MongoDB database.</p>
<p>The code is related with the other snippet <a href="http://djangosnippets.org/snippets/2872/">MongoDB data dump</a>.</p>
<p>To get it working, just create a <code>MONGODB_NAME</code> variable in settings, holding the name of your Mongo database. This can be edited to fit more your needs. …</p>
Freely redistributableMongoDB data dump
2013-01-03T09:33:54.695350-06:00jose_lpahttps://djangosnippets.org/snippets/2872/<p>This Django management command just dumps data from a given MongoDB collection into a JSON file.</p>
<p>To get it working, just create a <code>MONGODB_NAME</code> variable in settings, holding the name of your Mongo database. This can be edited to fit more your needs. The snippet requires Pymongo, since it uses …</p>
Freely redistributabledump_app_data: dumps application data to the application's fixtures directory
2011-07-28T13:55:45.105702-05:00woleverhttps://djangosnippets.org/snippets/2497/<p>Dumps DB data for each application to that application's fixtures directory.</p>
<p>For example:</p>
<pre><code>$ ./manage.py dump_app_data
...
$ hg status
M apps/foo/fixtures/dev.json
M apps/bar/fixtures/dev.json
</code></pre>
Freely redistributableDjango load global fixtures test helper
2011-07-25T18:14:34.443512-05:00vazhttps://djangosnippets.org/snippets/2496/<p>This lets you load global fixtures from a directory you set as <code>FIXTURES_ROOT</code> in your settings.py.</p>
<p>For example, setting <code>FIXTURES_ROOT</code> to <code>/path/to/myproject/fixtures/</code></p>
<p>I tend to like to keep fixtures that should be loaded when a new instance of a site is deployed, but not auto-loaded (so they won't rewrite any …</p>
Freely redistributableutf8-friendly dumpdata management command (no escape symbols) #2
2011-03-19T19:39:44.551171-05:00kmikehttps://djangosnippets.org/snippets/2397/<p>This is a version of <a href="http://djangosnippets.org/snippets/2258/">http://djangosnippets.org/snippets/2258/</a> that should work with special chars (e.g. quotes) in json data.</p>
Freely redistributableutf8-friendly dumpdata management command (no escape symbols)
2010-11-12T07:37:38.374550-06:00dirolhttps://djangosnippets.org/snippets/2258/<p>Adds <code>--pretty</code> option to django <code>./manage.py dumpdata</code> command, which produces pretty utf8 strings instead of ugly unicode-escaped shit:</p>
<pre><code>$ ./manage.py dumpdata app.pricingplan --indent=1
[
{
"pk": 1,
"model": "app.pricingplan",
"fields": {
"name": "\u0411\u0430\u0437\u043e\u0432\u044b\u0439",
}
},
{
"pk": 2,
"model": "app.pricingplan",
"fields": {
"name": "\u0425\u0443\u044f\u0437\u043e\u0432\u044b\u0439",
}
}
]%
./manage.py dumpdata app.pricingplan …</code></pre>
Freely redistributableJSON fixtures of Intl. country codes & dial-codes
2010-08-16T12:46:55.073413-05:00dibau_naum_hhttps://djangosnippets.org/snippets/2150/<p>Just a dump of a countries data, including standard codes & dial-codes, based on the following model:
- Country
-- name : CharField
-- code : CharField
-- dial_code : CharField
</p>
<p>Note that countries aren't unique, as some may have several intl. dial codes.
</p>
<p>You can parse it using script …</p>
Freely redistributableCSV to JSON Fixture
2009-08-11T14:48:45.548683-05:00briangershonhttps://djangosnippets.org/snippets/1680/<p><strong>This script converts a CSV file into a JSON file ready to be imported via <code>manage.py loaddata</code> like any other fixture data.</strong></p>
<p>It can be used manually to do a one-time conversion (for placing into a /fixtures folder), or used in a fabric script that automatically converts CSV to JSON …</p>
Freely redistributabletestshell
2009-05-11T14:59:38.585711-05:00bmihelachttps://djangosnippets.org/snippets/1500/<p>This commands runs a Python interactive interpreter with test database and data from the given fixture(s). It is usable if you want to play with test database.</p>
<p>See also testserver docs</p>
Freely redistributable