How to Import objects
<p>I use <code>populate_core.py</code> script to populate my sqlite database:</p>

<pre><code>import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')

import django
django.setup()

from core.models import *

def populate():
    north = add_region('North')
    south = add_region('South')

def add_region(name):
    r = Region.objects.get_or_create(name=name)[0]
    r.save()
    return r

if __name__ == '__main__':
    print ("Starting Core population script...")
    populate()
</code></pre>

<p>Then I want to use <code>populate_main.py</code> script to add some data to the database:</p>

<pre><code>import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')

import django
django.setup()

from core.models import *
from populate_core import *

def populate1():
    dist_one = add_district('Dist_one', north)

def add_district(name, region):
    d = District.objects.get_or_create(name=name, region=region)[0]
    d.save()
    return d

if __name__ == '__main__':
    print ("Starting main population script...")
    populate1()
</code></pre>

<p>Both the scripts are in the project main directory (where is manage.py). When i run the first script it works but when I run the second scripts it give an error:</p>

<pre><code>NameError: name 'north' is not defined
</code></pre>

<p>I think to be doing something wrong on the import line.</p>

<p>As alternative the 'north' object is in the database (db.sqlite3) so maybe I should look there?</p>

<p>Thank you for your help</p>