djangosnippets.org: Latest snippets tagged with 'import'http://djangosnippets.org/tags/import/2013-06-14T15:05:30.194689-05:00export to csv, import from csv
2013-06-14T15:05:30.194689-05:00peiweihttp://djangosnippets.org/snippets/2928/<p>This is a management command to export an app to csv files, or import from csv files.
Code originally from django-csvimport</p>
Freely redistributablecreate or update, then get, model instances from JSON/py dict
2011-12-05T07:50:10.129560-06:00anentropichttp://djangosnippets.org/snippets/2621/<p>Basically the idea is to import/update model instances from a json data that closely matches the model structure (i.e. identical field names)</p>
<p>From my answer to this question: <a href="http://stackoverflow.com/a/8377382/202168">http://stackoverflow.com/a/8377382/202168</a></p>
<p>See the original question for sample data format.</p>
Freely redistributablecheck database interity
2010-06-22T09:19:08.802351-05:00d2http://djangosnippets.org/snippets/2076/<p>Check database constraints after dirty import
</p>
Freely redistributableCSV to JSON Fixture
2009-08-11T14:48:45.548683-05:00briangershonhttp://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 redistributableDynamic import from an installed app
2009-04-02T12:52:18.899172-05:00Archatashttp://djangosnippets.org/snippets/1413/<p>This is an example how to dynamically import modules other than <code>models.py</code> from installed apps. It allows you to define the full module path just once in <code>INSTALLED_APPS</code> in the settings.</p>
<p>Using this technique makes it possible to write extensible and reusable apps as mentioned in <a href="http://djangotricks.blogspot.com/2009/02/abstract-models-and-dynamicly-assigned.html">Abstract Models and Dynamicly …</a></p>
Freely redistributablesyncdata command
2008-07-29T18:02:57.781718-05:00grahamhttp://djangosnippets.org/snippets/926/<p>A django admin command that takes a fixture and makes the target database the same as that fixture, deleting objects that in the database but not in the fixture, updating objects that are different in the database, and inserting missing ones.
Place this code in your_app/management/commands/syncdata.py
You will need to …</p>
Freely redistributableDynamic Template Loader
2008-07-03T22:01:48.048598-05:00jgeewaxhttp://djangosnippets.org/snippets/851/<p>This snippet provides support for dynamically importing templates. This helps you to avoid naming collisions and other problems. </p>
<p>The format is as follows:</p>
<ol>
<li><code>module.submodule.app:template.html</code></li>
<li><code>module.submodule.app:subfolder/template.html</code></li>
<li><code>module.submodule.app:/subfolder/template.html</code></li>
</ol>
<p>Assuming the module is located in '/var/', these would map (respectively) to:</p>
<ol>
<li><code>/var/module/submodule/app/templates/template.html</code></li>
<li><code>/var/module/submodule/app/templates/subfolder/template.html</code></li>
<li><code>/var/module/submodule/app/templates/subfolder/template.html</code></li>
</ol>
<p>The colon splits the the python module from the …</p>
Freely redistributableCSVImport
2008-06-06T11:38:48.210725-05:00sharkushttp://djangosnippets.org/snippets/788/<p>This is an awesome script! The original can be found here: http://www.djangosnippets.org/snippets/633/</p>
<p>I had to make a couple minor changes to get it working for me, so I thought I would share the love...</p>
Freely redistributablemodule_from_path
2008-05-15T10:21:51.420676-05:00simonhttp://djangosnippets.org/snippets/757/<p>I needed to dynamically import a module based on a path to that file on disk, without it necessarily being on the Python Path.</p>
Freely redistributableAutomagically import settings from installed applications
2008-01-31T08:03:06.767993-06:00jezdezhttp://djangosnippets.org/snippets/573/<p>Use this snippet at the end of your main settings.py file to automagically import the settings defined in each app of <code>INSTALLED_APPS</code> that begins with <code>APPS_BASE_NAME</code>.</p>
<p>Set <code>APPS_BASE_NAME</code> to the base name of your Django project (e.g. the parent directory) and put <code>settings.py</code> files in every app directory (next …</p>
Freely redistributableSimple Plone Migration
2008-01-18T15:46:29.745420-06:00msm-arthttp://djangosnippets.org/snippets/554/<p>This is a very simple script to do a <strong>simple</strong> migration from plone content to django.</p>
<p>ATNewsItems and PloneArticles are imported into the django model <em>Article</em> (with Foreignkey to the django models <em>File</em> and <em>Image</em>). ATDocuments are imported into the django model <em>Page</em>.</p>
<p><strong>Usage</strong></p>
<ol>
<li>Make sure that the …</li></ol>
Freely redistributableAutoload Django Models When Using ./manage.py shell
2008-01-09T10:29:45.987130-06:00sheatshttp://djangosnippets.org/snippets/540/<p>It's a pain to import all the Django models you want to use in the Python shell every time you start it. Here's how you can get IPython to autoload all your Django models for you every time you start the shell using ./manage.py shell. </p>
<p>Put the code in a …</p>
Freely redistributableMovable Type Import
2007-12-17T17:24:06.223770-06:00bretwalkerhttp://djangosnippets.org/snippets/515/<p>This is a quick and dirty way to import blog entries and comments from Movable Type.</p>
<p>Sorry I don't have time to document it better. Hopefully it will help you get started if you're looking to move from MT to Django.</p>
Freely redistributableMaxMind(R) GeoIP Lite CSV Import
2007-07-18T20:55:43.363148-05:00jbronnhttp://djangosnippets.org/snippets/328/<p>Use this script to import the Maxmind GeoIP lite CSV datasets into your database. This takes at least 200MB of RAM; the resulting database will be ~400MB. Stick in the same directory as the <a href="http://www.djangosnippets.org/snippets/327/">models</a>. Make sure to set <code>DEBUG=False</code> to prevent running out of memory during import.</p>
Freely redistributable