It's my first time trying to achieve the 'file upload functionality' and I need your help. I'm working on a legacy db and I'm supposed to do the file upload in a table that gets created this way:
CREATE TABLE  "LICENCE" 
(   "ID" NUMBER NOT NULL ENABLE, 
"VEH_ID" NUMBER NOT NULL ENABLE, 
"DTP_ID" NUMBER NOT NULL ENABLE, 
"LICENCENO" VARCHAR2(50 CHAR) NOT NULL ENABLE, 
"ISSUEDATE" DATE, 
"STARTDATE" DATE, 
"EXPIREDATE" DATE, 
"DOCPATH" VARCHAR2(500 CHAR), 
"CHECKFLAG" NUMBER(1,0) NOT NULL ENABLE, 
 CONSTRAINT "LIC_PK" PRIMARY KEY ("ID") ENABLE, 
 CONSTRAINT "LIC_DTP_FK" FOREIGN KEY ("DTP_ID")
  REFERENCES  "DOCTYPES" ("ID") ENABLE, 
 CONSTRAINT "LIC_VEH_FK" FOREIGN KEY ("VEH_ID")
  REFERENCES  "VEHICLES" ("ID") ENABLE)/
With inspectdb, I got this model:
class Licence(models.Model):
    id = models.DecimalField(unique=True, primary_key=True, max_digits=127, decimal_places=0)
    veh_id = models.ForeignKey(Vehicles, db_column='veh_id')
    dtp_id = models.ForeignKey(Doctypes, db_column='dtp_id')
    licenceno = models.CharField(max_length=200)
    issuedate = models.DateField(null=True, blank=True)
    startdate = models.DateField(null=True, blank=True)
    expiredate = models.DateField(max_length=2000, blank=True)
    docpath = models.CharField(max_length=200)
    checkflag = models.IntegerField()
    def __unicode__(self):
        return self.licenceno
How should I handle the upload?My thought after reading the django file upload documentation was to modify the docpath to filefield. Is that the right practice?Because I tried it and the form doesn't pass validation while I get "No file chosen". Can someone guide me through?
my views.py is:
def upload(request):
    if "doc-form" in request.POST:
        form = LicenceForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            form.save()
            return render_to_response('bingo.html', locals(), context_instance=RequestContext(request)
    else:
        form = LicenceForm()
    return render_to_response('upload.html', locals(), context_instance=RequestContext(request))
and the form in my template:
<form enctype="multipart/form-data" id="insertDocsForm" method="post" action='/upload/'>{% csrf_token %}
   <div class="id">
   {{ form.id.errors }}
    <label for="id"></label>
   {{ form.id }}
  </div>
  <div class="veh_id">
   {{ form.veh_id.errors }}
    <label for="veh_id">veh:</label>
  {{ form.veh_id }}
  </div>
  <div class="dtp_id">
   {{ form.dtp_id.errors }}
    <label for="dtp_id">dpt:</label>
   {{ form.dtp_id }}
  </div>
  <div class="licenceno">
   {{ form.licenceno.errors }}
    <label for="licenceno">lic:</label>
   {{ form.licenceno }}
  </div>
  <div class="issuedate">
   {{ form.issuedate.errors }}
    <label for="issuedate">isdate:</label>
   {{ form.issuedate }}
  </div>
  <div class="startdate">
   {{ form.startdate.errors }}
    <label for="startdate">stdate</label>
   {{ form.startdate }}
  </div>
    <div class="expiredate" >
   {{ docform.expiredate.errors }}
    <label for="expiredate">exdate:</label>
   {{ form.expiredate }}
  </div>
  <div class="docpath">
   {{ form.docpath.errors }}
    <label for="docpath"></label>
   {{ form.docpath }}
  </div>
  <div class="checkflag">
   {{ form.checkflag.errors }}
    <label for="checkflag"></label>
   {{ form.checkflag }}
  </div>
  <p>{{ form.errors }}
     {{ form.docpath.errors }}
  </p>
  <input type="hidden" name="doc-type" value="doc-form"
  <input type="submit" id="id_docSubmit"  value="Upload">
 </form>
 
    