backend/users/signals.py
def handle_avatar_on_change(sender, instance, **kwargs):
    """
    Deletes old file from filesystem
    when corresponding User object is updated
    with new file and compress the last one.
    """
    if not instance.pk:
        return
    try:
        old_avatar = sender.objects.get(pk=instance.pk).avatar
    except sender.DoesNotExist:
        return

    new_avatar = instance.avatar
    if old_avatar and old_avatar != new_avatar:
        if os.path.isfile(old_avatar.path):
            os.remove(old_avatar.path)

    if new_avatar:
        instance.avatar = compress_avatar(new_avatar)
        if os.path.isfile(new_avatar.path):
            os.remove(new_avatar.path)

    Deletes old file from filesystem
    when corresponding User object is updated
    with new file and compress the last one.
    
Deletes old file from filesystem
when corresponding User object is updated
with new file and compress the last one.
Deletes old file from filesystem when corresponding User object is updated with new file and compress the last one .
def handle_avatar_on_change(sender, instance, **kwargs):
    if not instance.pk:
        return
    try:
        old_avatar = sender.objects.get(pk=instance.pk).avatar
    except sender.DoesNotExist:
        return
    new_avatar = instance.avatar
    if old_avatar and old_avatar != new_avatar:
        if os.path.isfile(old_avatar.path):
            os.remove(old_avatar.path)
    if new_avatar:
        instance.avatar = compress_avatar(new_avatar)
        if os.path.isfile(new_avatar.path):
            os.remove(new_avatar.path)
def handle_avatar_on_change ( sender , instance , ** kwargs ) : if not instance . pk : return try : old_avatar = sender . objects . get ( pk = instance . pk ) . avatar except sender . DoesNotExist : return new_avatar = instance . avatar if old_avatar and old_avatar != new_avatar : if os . path . isfile ( old_avatar . path ) : os . remove ( old_avatar . path ) if new_avatar : instance . avatar = compress_avatar ( new_avatar ) if os . path . isfile ( new_avatar . path ) : os . remove ( new_avatar . path )
Deletes old file from filesystem
when corresponding User object is updated
with new file and compress the last one.
Deletes old file from filesystem when corresponding User object is updated with new file and compress the last one .
"""
    Deletes old file from filesystem
    when corresponding User object is updated
    with new file and compress the last one.
    """
sender
instance