2 from django.core.management.base import BaseCommand
3 from isbn.models import IsbnPool
6 class Command(BaseCommand):
7 def add_arguments(self, parser):
8 parser.add_argument('filename')
10 def handle(self, filename, **options):
11 with open(filename) as f:
16 if d['model'] == 'isbn.isbnpool':
17 pool_map[d['pk']], created = IsbnPool.objects.get_or_create(
19 suffix_from=f['suffix_from'],
20 suffix_to=f['suffix_to'],
21 ref_from=f['ref_from'],
23 if d['model'] == 'isbn.onixrecord':
24 pool = pool_map[f['isbn_pool']]
25 isbn, created = pool.isbn_set.get_or_create(
28 isbn.wl_data = json.dumps(f, indent=4, ensure_ascii=False)
29 isbn.save(update_fields=['wl_data'])