I need to download and read CSV and then save to the database. I am new to below - this is what I have so far used using "django-adapters" (http://django-adaptors.readthedocs.org/en/latest/index.html). I know this is not much, just do it to find out more :)
I am struggling with a bit of my view (below). I do not know how to load and then read the file into the CodeCSvModel () function? Can anyone help explain? Thank you very much.:)
views.py
from django.template import RequestContext from django.shortcuts import render_to_response from web.forms import codeUploadForm from web.csvTools import CodeCSvModel def codeImport(request):
forms.py
class codeUploadForm(forms.Form): file = forms.FileField() place = forms.ModelChoiceField(queryset=Incentive.objects.all())
csvTool.py
from datetime import datetime from adaptor.fields import * from adaptor.model import CsvModel, CsvDbModel, ImproperlyConfigured,\ CsvException, CsvDataException, TabularLayout, SkipRow,\ GroupedCsvModel, CsvFieldDataException from web.models import * class CodeCSvModel(CsvModel): codeid = CharField() remotecode = CharField() active = BooleanField() created = DateField() modified = DateField() incentiveid = CharField() class Meta: delimiter = ";" dbModel = Code
source share