Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9089741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:12:50+00:00 2026-06-16T22:12:50+00:00

I need to upload and read a CSV then save to database. I’m a

  • 0

I need to upload and read a CSV then save to database. I’m a beginner and below is what I have achieved so far using ‘django-adaptors’ (http://django-adaptors.readthedocs.org/en/latest/index.html) I know its not a lot but I’m just doing this to learn more 🙂

I’m struggling in the view bit of my code (below). I don’t know how to upload then read the file into to CodeCSvModel() function? Could anyone help explain? Many thanks. 🙂

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):
    # If we had a POST then get the request post values.
    if request.method == 'POST':
        form = codeUploadForm(request.POST, request.FILES)
      # handle_uploaded_file(request.FILES['file'])

                ====[HELP HERE]=====

        #form = codeUploadForm(request.POST)

        CodeCSvModel.import_from_file(form['file'])



    else:
         form = codeUploadForm()
         context = {'form':form}
         return render_to_response('import.html', context, context_instance=RequestContext(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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:12:51+00:00Added an answer on June 16, 2026 at 10:12 pm

    Django only keeps the uploaded file in memory if it is 2.5MB or smaller, otherwise it writes to a temporary location.

    The step you’re missing is where you actually write the file from memory/temporary location to disk somewhere, e.g.

    if request.method == 'POST':
        form = MyForm(request.POST, request.FILES)
        if form.is_valid():
            uploaded_file = request.FILES['html-file-attribute-name']
    
            # Write the file to disk
            fout = open("path/to/save/file/to/%s" % uploaded_file.name, 'wb')
            for chunk in uploaded_file.chunks():
                fout.write(chunk)
            fout.close()
    

    Chunking is the way to go if the file is very large, because Django will read each chunk of the file into memory before writing to disk. If you use read() instead, it will read the entire file into memory, so chunks is your best bet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually I have to upload pdf files and need to read on my website
I need to upload a file in a database using an input form in
I need to allow users to upload PDF documents that other users will read.
I'm trying to upload a file via URLConnection, but I need to read/write it
I need to upload a single image to server. The project is using .NET
I need to upload an image to my site, using either a drag and
I'm trying to upload and parse json files using django. Everything works great up
I want to upload files on my website. I have read at a few
I have an upload field and I want to read user input with jquery
I am using Django to read an ajax uploaded file to store it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.