Also, don't forget the multi-part in your template: <FORM action="" enctype="multipart/form-data" method="post">
On Sun, Sep 9, 2012 at 2:29 PM, Joseph Mutumi <jjmut...@gmail.com> wrote: > I'm assuming you are using the forms.ModelForm for your model? Say > LicenceForm? > > class LicenseForm(forms.ModelForm): > class Meta: > model = License > > According to the doc you have to pass all relevant QueryDicts to the form > __init__ > when you are creating a bound instance. In a nutshell make sure your doing: > > # The view function > def handle_upload(request): > # Get request logic ... > if request.method == "POST": > form = LicenceForm(request.POST, request.FILES) > if form.is_valid(): > #save input data > form.save() > #continue with other stuff > > More on the docs: > https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files-with-a-model > > > > On Sun, Sep 9, 2012 at 5:56 PM, mapapage <mapap...@gmail.com> wrote: > >> Hi! 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 table: >> >> 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 file upload >> documentation was to modify the docpath to filefield. Is that the right >> practice?Because I tried it, and the form doesn't validate, I get the error >> "No file chosen". Can anyone guide me through this?Thank you.. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/django-users/-/eo_e4m3hye8J. >> To post to this group, send email to django-users@googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.