Skip to content
Snippets Groups Projects
Commit 39e631d4 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add a custom django command import_v1_data

this is only a draft, still with much hardcoded ugliness...
parent 02c69d73
No related branches found
No related tags found
No related merge requests found
from django.core.management import BaseCommand
import mysql.connector
from ippidb.models import Bibliography
class Command(BaseCommand):
help = "Import data from the local v1 database"
def handle(self, *args, **options):
conn = mysql.connector.connect(host="localhost",user="root",password="ippidb", database="ippidb")
cursor = conn.cursor()
cursor.execute("""SELECT * FROM biblio""")
rows = cursor.fetchall()
Bibliography.objects.all().delete()
self.stdout.write(self.style.SUCCESS('Successfully flushed bibliography table'))
for row in rows:
try:
b = Bibliography()
b.source = 'PM'
b.id_source = row[2]
b.save()
except Exception as e:
self.stdout.write(self.style.ERROR('Failed inserting {}'.format(row[2])))
else:
self.stdout.write(self.style.SUCCESS('Successfully inserted {}'.format(row[2])))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment