-
Notifications
You must be signed in to change notification settings - Fork 1
/
populate.py
63 lines (52 loc) · 1.6 KB
/
populate.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
import os
import django
sys.path.append('listings')
os.environ['DJANGO_SETTINGS_MODULE'] = 'listings.settings'
django.setup()
from main.models import Condition, Location, ListingType
conditions = ['Like New', 'Very Good', 'Good', 'Acceptable']
if not Condition.objects.all():
print("Adding Conditions in the database:")
for condition in conditions:
Condition(condition = condition)c.save()
print(f"\tAdded {condition}")
else:
print('There are already some Condition objects in the database. Skipping...')
locations = [
'Krishna Hostel (DoH 1)',
'Bhagirathi Hostel (DoH 2)',
'Brahmaputra Hostel (DoH 3)',
'Ganga Hostel (DoH 4)',
'Mahanadi Hostel (SoH 1)',
'Rushikulya Hostel (SoH 2)',
'Daya Hostel (SoH 3)',
'Kaveri Hostel (SoH 4)',
'Yamuna Hostel (SoH 5)',
]
if not Location.objects.all():
print("Adding Locations in the database:")
for location in locations:
Location(location = location).save()
print(f"\tAdded {location}")
else:
print('There are already some Location objects in the database. Skipping...')
categories = [
'Bags/Luggage',
'Bicycles',
'Books',
'Electronics',
'Furniture',
'Gym Equipment',
'Musical Instruments',
'Pillow/Mattresses',
'Sports Equipment',
'Stationary'
]
if not ListingType.objects.all():
print("Adding ListingTypes in the database:")
for category in categories:
ListingType(name = category).save()
print(f"\tAdded {category}")
else:
print('There are already some ListingType objects in the database. Skipping...')