Advancing-the-Blog icon indicating copy to clipboard operation
Advancing-the-Blog copied to clipboard

upload_location not working for the first post

Open BigBorg opened this issue 7 years ago • 1 comments

def upload_location(instance, filename):
    #filebase, extension = filename.split(".")
    #return "%s/%s.%s" %(instance.id, instance.id, extension)
    PostModel = instance.__class__
    new_id = PostModel.objects.order_by("id").last().id + 1
return "%s/%s" %(new_id, filename)

This does not work if there is no post in the database. Add some exception handling and set new_id default to 1 would work.

BigBorg avatar Apr 25 '17 02:04 BigBorg

Also, use post_delete signal to delete image file when deleting a post instance would be good.

BigBorg avatar Apr 25 '17 02:04 BigBorg