import
xlrd
from
.models
import
Course
from
organization.models
import
CourseOrg
def
post(
self
, request,
*
args,
*
*
kwargs):
if
'excel'
in
request.FILES:
course
=
Course()
data
=
xlrd.open_workbook(request.FILES[
'excel'
].name)
table
=
data.sheets()[
0
]
nrows
=
table.nrows
for
j
in
range
(
1
, nrows):
courseorg
=
table.row_values(j)[
0
]
course.org_id
=
CourseOrg.objects.get(name
=
courseorg).
id
course.name
=
table.row_values(j)[
1
]
course.desc
=
table.row_values(j)[
2
]
course.image
=
table.row_values(j)[
3
]
…………
course.save()
return
super
(CourseAdmin,
self
).post(request, args, kwargs)