I want to update one field of my model after post save. For that I am using post_save signal but when I try to save the model it always get trapped in some kind of infinite loop and in the end I am getting max, recursion depth error
My code is as follows :
class UserProfile(models.Model):
.
.
.
def profile_thumbanil(sender, created, instance , **kwargs):
profile = UserProfile.objects.get(id = instance.id)
thumb = handlers.create_thumbanil(profile.image, profile.user_id)
profile.thumbnail_image = thumb
profile.save()
post_save.connect(profile_thumbanil, sender=UserProfile)
I don't know what's the error here. If anyone can tell me another way of saving the data after post_save then that will be also fine.
Thanks
Edit :
save() will not work in my case because I am creating the thumbnail of images and the script which I using resize the images which are already exist on server and thus untill the save() finished its work image will not be saved on server and thus I cannot resize it that's why I can only run my function after save() finished its work so that image will be saved on server and I can resize it.
I can use Update() when user try to save images via UI and in that case my function works because Image is already saved into db but when admin (django-admin) try to upload an image then issue comes. So I need to call my function in such a way that whenever django admin save/edit profile images I can call my function but as I said my function only works after actual save() finished its work.