-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
28 lines (21 loc) · 800 Bytes
/
data.py
File metadata and controls
28 lines (21 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from datetime import datetime
import json
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rentify.settings')
django.setup()
from home.models import CustomUser, Property
def import_data_from_json(file_path):
with open(file_path, 'r') as file:
data = json.load(file)
for item in data:
model_name = item['model']
fields = item['fields']
if model_name == 'app.Property':
owner_id = fields.pop('owner')
print(owner_id)# Get owner ID and remove from fields
owner = CustomUser.objects.get(pk=owner_id)
property = Property.objects.create(owner=owner, **fields)
if __name__ == "__main__":
file_path = "./data.json"
import_data_from_json(file_path)