Thanks a lot! It works for FileFiels as well!

Yours,
Guillaume.

Le mardi 08 mai 2007 � 00:20 +0000, scadink a �crit :
> File uploads haven't been completed in newforms.  It's not a great
> situation, but that's what happens with software that's currently in
> development.
> 
> What I did in my view that worked:
> 
> p = Picture()
> p.title = clean_data['title']
> p.save_image_file(image['filename'], image['content'])
> 
> Basically, the relevant part is the save_blank_file (where blank is
> the name of the part of the model to be saved).
> 
> Hopefully this will work for you!
> Sean.
> 
> On May 7, 3:11 pm, guillaume <[EMAIL PROTECTED]> wrote:
> > Well, my message was maybe a little long. I still have not found answers
> > to my problem.
> > To make it short, Is there anywhere a short example of file upload using
> > newform ?
> > The most simple thing with a model with 1 FileField, the smallest
> > template and form associated and the handling code.
> >
> > That would be great, and probably useful for some other django beginers.
> >
> > Yours,
> > Guillaume.
> >
> > Le lundi 07 mai 2007 ? 08:41 -0700, [EMAIL PROTECTED] a ?crit :
> >
> > > Hello everybody.
> >
> > > I am a Django newbie experimenting with some stuff. I am very
> > > impressed by the framework, that made me want to learn more about it.
> > > I am trying to do some file upload but I have a problem.
> > > I tried many information sources but could not find a simple example
> > > of what I am trying to do. I have a few question...
> >
> > > Well, It should be very simple, I just want to upload a file on the
> > > server on the MEDIA directory.
> > > I use the up to date SVN version ( 5156 ).
> >
> > > I put sipets of code below, the things I dont anderstand are:
> > > * The {{form.updateFile_file}} tag produces nothing the first time I
> > > load my page. Is it normal behavior?
> >
> > > * The validation raises an AttributeError with message: 'dict' object
> > > has no attribute 'startswith'
> > > The lower part of the stack is :
> > > /home/guillaume/dev/Python/django_src/django/db/models/fields/
> > > __init__.py in isWithinMediaRoot
> > >  628.  # If the raw path is passed in, validate it's under the
> > > MEDIA_ROOT.
> > >  629. def isWithinMediaRoot(field_data, all_data):
> >
> > >  630. f = os.path.abspath(os.path.join(settings.MEDIA_ROOT,
> > > field_data)) ...
> >
> > >  631. if not
> > > f.startswith(os.path.abspath(os.path.normpath(settings.MEDIA_ROOT))):
> > >  632. raise validators.ValidationError, _("Enter a valid filename.")
> >
> > > * If I disable the validation, I have an error because Django tries to
> > > insert the file data into the database as a string...
> >
> > > Well I probably missed something very simple, but I cannot figure
> > > it ...
> >
> > > Might a Django Guru engilten me ?
> >
> > > Yours,
> > > Guillaume.
> >
> > > ----------------------------------------------------------------------------
> >
> > > My model :
> >
> > > #-----------------------------------------------------------------------------
> > > class StockUpdateFile( models.Model ):
> >
> > >     updateFile  = models.FileField( upload_to = 'updatefiles/%Y/%m/
> > > %d' )
> > >     fdate       = models.DateField( auto_now_add = True )
> >
> > >     def __str__( self ):
> > >         return "file %1-%2-%3" % str( distributor ) % str( fdate ) %
> > > str( updateFile )
> >
> > >     class Admin:
> > >         pass
> >
> > > --------------------------------------------------------------------------------------------------------------
> > > The form is:
> >
> > > class UploadForm( forms.Form ):
> > >     updateFile = forms.Field( widget = forms.FileInput() )
> >
> > > ----------------------------------------------------------------------------------------------------------------
> > > My template is:
> >
> > > <form enctype="multipart/form-data"  action="/stock/uploadfile/"
> > > method="post" >
> >
> > >           <table>
> > >           {{form.updateFile}}:{{form.updateFile_file}}
> > >           </table>
> > >           <input type="submit" value="Upload File" />
> > > </form>
> >
> > > -----------------------------------------------------------------------------------------------------------------
> > > And the code handling the form is:
> >
> > > def uploadFile(request, template='uploadfile.html' ):
> >
> > >     errors = {}
> >
> > >     form = UploadForm()
> >
> > >     if( request.FILES ):
> >
> > >         manip = StockUpdateFile.AddManipulator()
> > >         newData = request.POST.copy()
> > >         newData.update( request.FILES )
> >
> > >         errors = manip.get_validation_errors( newData )
> >
> > >         if( not errors):
> >
> > >             manip.do_html2python( newData )
> > >             newFile = manip.save( newData )
> > >         else:
> > >             form = UploadForm()
> >
> > >     return render_to_response( template,
> > >                                context_instance =
> > > RequestContext( request, {'form': form,
> >
> > > 'errors' : errors } ))
> 
> 
> > 
> 


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to