-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_inventory.py
49 lines (35 loc) · 1.17 KB
/
load_inventory.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
import sys,os
# Full path and name to your csv file
filename = "CWCInventory.csv"
# Full path to your django project directory
your_djangoproject_home="/home/sgrobelny/desktop/seb-django/mysite"
print your_djangoproject_home
sys.path.append(your_djangoproject_home)
print sys.path
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
application = get_wsgi_application()
from main.models import Inventory
import csv
dataReader = csv.reader(open(filename), delimiter=',', quotechar='"')
for row in dataReader:
# Ignore the header row, import everything else
if row[0] != 'date' or row[0] != 'last review':
inventory = Inventory()
inventory.packaged = row[1]
inventory.color = row[2]
inventory.variety = row[3]
inventory.lot = row[4]
inventory.units = row[5]
inventory.storage = row[6]
inventory.year = row[7]
inventory.ava = row[8]
inventory.alc = row[9]
inventory.chemanalysis = row[10]
inventory.current = row[11]
inventory.pending = row[12]
inventory.other = row[13]
inventory.promised = row[14]
inventory.available = row[24]
inventory.comments = row[25]
inventory.save()