Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- regions_communes_upload(request):
- template = 'regions_communes_upload.html'
- prompt = {
- 'order': 'Orden del Excel debe ser cprovin, region, cpoblac,commune'
- }
- if request.method == "GET":
- return render(request,template,prompt)
- rc_file = request.FILES['file']
- if not rc_file.name.endswith('.csv'):
- messages.error(request,'Este no es un archivo CSV')
- data_set = rc_file.read().decode('UTF-8')
- io_string = io.StringIO(data_set)
- next(io_string)
- for column in csv.reader(io_string, delimiter=',', quotechar="|"):
- _, created = Region.objects.update_or_create(
- cprovin = column[0],
- name = column[1]
- ), temp = Commune.objects.update_or_create(
- cpoblac = column[2],
- name = column[3],
- region = column[0]
- )
- context = {}
- return render(request,template, context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement