2

i have the following files

models.py

Class Trip(models.Model)

featured = models.BooleanField(default=False, help_text='Tags this trip as a featured trip.')
top_ten_trip = models.BooleanField(default=False)
header_image = models.ImageField(help_text='This is the image shown when viewing the details for this trip.', upload_to='images/', blank=True, null=True)
map_image = models.ImageField(help_text='The map image for this trip.', upload_to='images/', blank=True, null=True)
.....

and so on

admin.py

class TripAdmin(admin.ModelAdmin):

list_display = ('name', 'code', 'category', 'supplier', 'active', 'featured', 'top_ten_trip',)
search_fields = ('name', 'code',)
list_filter = ('category', 'featured', 'top_ten_trip',)
filter_horizontal = ('countries', 'related_trips',)

The field appear with browse button in admin something like this Header image: Currently: images/comfort_japan.jpg Change: Delete this file

Map image: Currently: images/map_japan_.jpg Change: Delete this file

Now the Problem :- When i click on Delete this imagefile( images/comfort_japan.jpg ) it get removed for that instant but does not deleted when i press save button on admin.

I want when i click on delete this file and press save it should get deleted.

What mistake i am doing or what am i missing ?

Thanks in advance.

the_game
  • 261
  • 1
  • 5
  • 16

2 Answers2

2

This was intentionally changed in Django 1.3, see Django Ticket #15224.
You need to implement file deletion yourself. Check related posts:

Community
  • 1
  • 1
Scillon
  • 320
  • 1
  • 8
  • What i want is the ImageField which Django1.4b contains.A checkbox which ask for clear image .How can i achieve that ? I am looking through Django 1.4b code really hard to figure out what they have done.I am in Django1.2.5 .How can i use post_save signal to achieve this – the_game Mar 04 '12 at 12:27
  • @the_game The Clear checkbox (appearing next to the image name if `blank=True` was set on the ImageField) when selected only removes the image from the model (db) but not deleting it from the disk. To override this with signals check [this](http://obroll.com/automatically-delete-file-in-filefield-django-1-3-when-object-record-deleted/) – Scillon Mar 04 '12 at 14:19
  • Write i agree it will only remove and not delete. This snippet also removes but not delete. As i have searched remove is the better approach rather than delete but thanks i made some concept on signals – the_game Mar 05 '12 at 11:29
0

Hi All I solved my problem by using snippet 1633

http://djangosnippets.org/snippets/1633/ .It works pretty fine.

the_game
  • 261
  • 1
  • 5
  • 16