Created
August 26, 2014 17:17
-
-
Save dandye/9fad89c2846f4e2548b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ddye@ubuntu:~# cd /usr/local/otm/ | |
#ddye@ubuntu:/usr/local/otm# source env/bin/activate | |
#(env)ddye@ubuntu:/usr/local/otm# cd app/opentreemap/ | |
#(env)ddye@ubuntu:/usr/local/otm/app/opentreemap# python manage.py shell | |
#Python 2.7.3 (default, Feb 27 2014, 19:58:35) | |
#[GCC 4.6.3] on linux2 | |
#Type "help", "copyright", "credits" or "license" for more information. | |
#(InteractiveConsole) | |
#>>> | |
from django.db import models | |
from django.conf import settings | |
from otm2 import local_settings | |
import psycopg2 | |
from psycopg2.extras import RealDictCursor | |
User = models.loading.get_model("treemap", "User") | |
Species = models.loading.get_model("treemap", "Species") | |
Instance = models.loading.get_model("treemap", "Instance") | |
ddye = User.objects.get(email='ddye@usf.edu') | |
instance = Instance.objects.get(id=12) | |
conn = psycopg2.connect("host=localhost dbname=otm1 user=otm_user password=redacted") | |
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) | |
cur.execute("SELECT * FROM treemap_species;") | |
recs = cur.fetchall() | |
for rec in recs: | |
species = Species() | |
species.common_name = rec["common_name"] or '' | |
species.species = rec["species"] | |
species.genus = rec["genus"] | |
species.instance = instance | |
species.save_with_user(ddye) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment