I have been working on my CSV upload for a little while now, and I finally got it working (sort of haha) As it stands right now, my code will only pull the first record from the CSV file, and I have been looking at it too long, and Im sure I am missing something. Here is my views.py
@login_required
def importClient(request):
print "its being called"
if request.FILES:
form = ImportClientForm(request.POST, request.FILES)
if form.is_valid():
print "its valid!!"
if '.csv' in request.FILES['contact_file'].name:
print "It's a CSV file!!!"
importfile = csv.DictReader(request.FILES['contact_file'])
for row in importfile:
#establish client name
cn = row.get('Customer', None)
c = Clients(
client_name = cn,
phone = "",
phone_cell = "",
fax = "",
email = "",
add_1 = "",
add_2 = "",
city = "",
province = "",
country = "",
postal = "",
)
#check to see if client exists already
already_there = Clients.objects.filter(client_name = cn)[:1]
if not already_there:
c.save()
return HttpResponseRedirect('/clients/')
else:
form = ImportClientForm()
return render_to_response('clients/importClients.html', {
'form': form}, context_instance=RequestContext(request))
Is there something that I am missing, I am sure its really simple.
Thanks, Steve