I thought I had a custom widget which would allow images to be deleted
working and was dead chuffed (http://groups.google.com/group/django-
users/browse_thread/thread/ebf646208fa8880f/c22f87e85b5d78ef?
lnk=gst&q=admin+image#c22f87e85b5d78ef) but unfortunately it doesn't
work.  I have spent the whole evening trying to work out what exactly
is going on and have to admit defeat.

The widget adds a delete checkbox next to each image as well as
displaying it, then in the save_model() method it checks to see if
this checkbox was set and clears the field if it is.

 def save_model(self, request, obj, form, change):

            #handle delete checkbox for pics
            if request.POST.get('delete_pic1','off')=='on':
                obj.pic1=''


This is what happens:
1. create a new record and add an image - OK
2. edit the record - image is displayed - make no changes and click
save - OK
3. edit the record again and the image is gone - NOT OK!

This is my thinking so far:
I wondered if I needed to set the value when assigning the widget to
the field, but as the image is displayed in step 2, I recon not.
I tried also saving the value of pic in a hidden field and modifying
save_model

            if request.POST.get('delete_pic2','off')=='on':
                obj.pic2=''
            else:
                obj.pic2=request.POST.get('old_pic2','')

But it never even gets uploaded in step 1. So I tried:

           try:
                p=request.FILES.get('pic1')
            except:
                if request.POST.get('delete_pic1','off')=='on':
                    obj.pic1=''

And this goes back to the behaviour in the original step.

I have tried putting in various breaks in the django code in files.py
to try and understand what is happening but my lack of debugging
skills are not helping!  The client is expecting to see this tomorrow
so despite having plagued this list today with my problems, I hope to
prevail upon you to help me one more time...




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