hi Ronghui,
may i know what do u mean by "didnt save the file" using the form save
() method?

Do u mean that in Guptha's views.py, the function should have:
form.save()

in order to save the image?

Best Regards.

On Jul 24, 7:20 pm, Ronghui Yu <stone...@gmail.com> wrote:
> You didn't save the file in the form save() method. In the form,
> self.cleaned['photo1'] is an object of UploadedFile(may be typo error)
> You need to save it if you handle the save method by yourself
>
> Actually, you don't need to redefine those fields in the form if what
> you do is the same as what Django does by default.
>
> guptha ??:
>
>
>
> > hi friends
> > I 'm facing a wried behavior of Imageupload
> > In Models.py
> > class Market(...)
> >        title_name=models.CharField(max_length=125)
> >        photo1  = models.ImageField(upload_to= 'img/marketplace/%Y/%m/
> > %d', null=True, blank=True)
>
> > In views.py
> > def postyour_adds(request):
> >     if request.method=='POST':
> >         form=MarketplaceForm(request.POST,request.FILES)
> >         if form.is_valid():
> >             postdict=request.POST.copy()
> >             newmarket=form.save()
> >             .............
> >      .............
>
> > In forms.py
> > class MarketplaceForm(forms.Form):
> >         title_name = forms.CharField(max_length=125)
> >         photo1 = forms.ImageField(widget=forms.FileInput
> > (),required=False)
> >         # I tried with another way in vain
> >         #photo1 = forms.Field(widget=forms.FileInput(),required=False)
> >           def save(self):
> >                         new_market =Marketplace.objects.create
> > (title_name=self.cleaned_data['title_name'],
>
> > photo1=self.cleaned_data['photo1'],
> >            return new_market
>
> > In html file
> > {% block content %}
> > <h3> Enter your choice</h3>
> >    <table>
> >   <form action="" method="post" enctype="multipart/form-data" >
> >       {{ form.as_table }}
> >       <input type="submit" value="Create the account">
> >   </form>
> >   </table>
> > {% endblock %}
>
> > Issue is that image names are stored in Database but when i search in
> > my file system I could not find the image .
> > when i repeat the same in admin site i could see the file name with
> > the path i specified in Models.py and the actual image file is present
> > in the specified location .
> > I'm not sure why this wried behavior when i upload images from the
> > user page .Why is that the image is not constructed in my file system
> > Your solution is very much appreciated
> > thanks
>
> --
> Ronghui Yu <mailto:stone...@163.com>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to