added wherehouse json
This commit is contained in:
22
core/apps/wherehouse/management/commands/import_warehouse.py
Normal file
22
core/apps/wherehouse/management/commands/import_warehouse.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import json
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from core.apps.wherehouse.models import WhereHouse
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('file_path', type=str, help='Path to JSON file')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
file_path = options['file_path']
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
for item in data['data']['warehouses']:
|
||||
WhereHouse.objects.get_or_create(
|
||||
name=item['name']
|
||||
)
|
||||
|
||||
self.stdout.write("Warehouses added")
|
||||
Reference in New Issue
Block a user