Ah that makes sense a little, so just for html. But to clarify it seems like the forms.fileField can be used in a model in place of models.filefield, as in the code below. I have gotten models.FileField(uploadTo = /somedir) to work just fine in development. Is there some advantage to the formsHandleUpload example below?:
> > def handle_uploaded_file(f): > destination = open('some/file/name.txt', 'wb+') > for chunk in f.chunks(): > destination.write(chunk) > destination.close() Thanks Ivo On Wed, Nov 9, 2011 at 4:45 PM, Ivo Brodien <i...@brodien.de> wrote: > Hi, > > well they are different things. > > models.FileField is used to define a field of a model (usually to store in > a DB, metadata in this case) > > The forms.FileField defines a field in a HTML form which can receive File > uploads and then can be used to do sth on the server. > > I think you will get the concept when you take a look at ModelForms. These > are forms which are tied to a model and can even be automatically be > generated as in the admin app. If you have a model with a FileField this > ModelForm will have a forms.FileField for the FileField. > > in a few words: > A models.FileField knows about database options, a forms.FileField knows > about HTML and how it has to be rendered via its widget. > > Bye > Ivo > > On Nov 8, 2011, at 3:16, Eli_West <e...@trakdrop.com> wrote: > > > Hello, > > > > When creating a working with the models and views to upload files what > > is the difference between models.FileField and forms.FileField? Just a > > practical usage explanation would be good at this point. > > > > i can't find any comparison of the two but django directions and > > examplesh use one or the other. I've gotten forms that use > > models.FileField calls to work but the forms.FileField seems to act > > up. For example this general django directions use the > > form.fileField: > > > > from django import forms > > > > class UploadFileForm(forms.Form): > > title = forms.CharField(max_length=50) > > file = forms.FileField() > > > > def upload_file(request): > > if request.method == 'POST': > > form = UploadFileForm(request.POST, request.FILES) > > if form.is_valid(): > > handle_uploaded_file(request.FILES['file']) > > return HttpResponseRedirect('/success/url/') > > else: > > form = UploadFileForm() > > return render_to_response('upload.html', {'form': form}) > > > > def handle_uploaded_file(f): > > destination = open('some/file/name.txt', 'wb+') > > for chunk in f.chunks(): > > destination.write(chunk) > > destination.close() > > > > All the chunks() calls and others seem helpful but the > > models.FileField ( upload to = /somedir) gets things done in a snap. > > > > Any recommendations? > > > > -- > > 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. > > -- 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.