formdata: partial disable autocommit when feeding formdatas
This commit is contained in:
parent
449c4ee6d4
commit
751c08d693
|
@ -1,7 +1,6 @@
|
|||
import csv
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils.dateparse import parse_datetime
|
||||
from django.db import transaction
|
||||
|
||||
from eodb.events.models import Formdata
|
||||
|
||||
|
@ -12,8 +11,11 @@ class Command(BaseCommand):
|
|||
parser.add_argument('filename', metavar='FILENAME')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for row in csv.reader(open(options['filename'])):
|
||||
if not parse_datetime(row[1]):
|
||||
transaction.set_autocommit(False)
|
||||
for i, row in enumerate(open(options['filename'])):
|
||||
datetime = parse_datetime(row)
|
||||
if not datetime:
|
||||
continue
|
||||
event, created = Formdata.objects.get_or_create(
|
||||
author_datetime=parse_datetime(row[1]))
|
||||
Formdata(author_datetime=datetime).save()
|
||||
if i % 1000 == 0:
|
||||
transaction.commit()
|
||||
|
|
Reference in New Issue