wherehouse: change command

This commit is contained in:
behruz-dev
2025-10-30 23:43:04 +05:00
parent 70d39f531f
commit c7595f6904
2 changed files with 674 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ import json
from django.core.management import BaseCommand
from core.apps.wherehouse.models import WhereHouse
from core.apps.accounts.models import User
class Command(BaseCommand):
@@ -15,8 +16,12 @@ class Command(BaseCommand):
data = json.load(f)
for item in data['data']['warehouses']:
WhereHouse.objects.get_or_create(
wherehouse, create = WhereHouse.objects.update_or_create(
name=item['name']
)
full_names = []
for user in item['users']:
full_names.append(user['full_name'])
users = User.objects.filter(full_name__in=full_names)
wherehouse.users.set(users)
self.stdout.write("Warehouses added")