On 26-Dec-07, at 9:01 AM, Malcolm Tredinnick wrote:

>
>
> On Wed, 2007-12-26 at 08:53 +0530, Kenneth Gonsalves wrote:
>>
>> On 25-Dec-07, at 7:53 PM, l5x wrote:
>>
>>> Hm, I didn't have this error with my PhotoForm. You can look at it
>>> here: http://groups.google.com/group/django-users/browse_thread/
>>> thread/6693f3294e710eab
>>
>> when you want to change the photo in the form, when the form comes up
>> is the filename of the original photo shown?
>
> What you're seeing is normal browser behaviour. They don't populate  
> file
> upload fields with any kind of initial data. As Joseph mentioned,  
> that's
> a special case that will need to be built into ModelForms: manually  
> copy
> over the initial data before validating for file fields.

showing the filename is a minor problem which can be solved. The  
problem is that the file data is not sent to the form. The other data  
in the model which has the ImageField is being sent to the form. So  
when the form is shown, if I leave the fileinput blank (I dont change  
the file, only change other fields), I get a validation error 'this  
field is required' on the fileinput. The code is here:

class Photoform(ModelForm):
     class Meta:
         model = Photo
         fields = ('matter','photo','clss')

@user_passes_test(lambda u: u.is_anonymous()==False ,login_url="/web/ 
login/")
@transaction.commit_on_success
def addphoto(request,pageid=None,rank=None,id = None):
     """adds a photo and optional blurb to a page given the page id,  
rank
         """
     brick = 'photo'
     # checkparams just returns the existing Photo object
     instance = checkparams(brick,pageid=pageid,rank=rank,id=id)
     if request.POST:
         if not instance:
             rnk = int(rank) +1
             instance = Photo(page_id = pageid,rank=rnk)
         form =Photoform(request.POST,request.FILES,instance=instance)
         if form.is_valid():
             if not id:
                 adjustrank(pageid,rnk,True)
             f=form.save()

             return HttpResponseRedirect('/web/reviewpage/%d/' % int 
(f.page_id))
     else:

         form = Photoform(instance=instance)
     t = loader.get_template('web/addbrickfile.html')
     c = Context(
                 {
                  'request':request,
                  'form': form,
                  })
     return HttpResponse(t.render(c))

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/
Foss Conference for the common man: http://registration.fossconf.in/web/



--~--~---------~--~----~------------~-------~--~----~
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