def user_avatar_dir(instance, filename):
    """
    Helper functions for determining file upload locations.
    Files will be uploaded to [MEDIA_ROOT]/user_<id>/avatar/<filename>
    :param instance: an instance of the model where the ImageField is defined
    :param filename: the filename that was originally given to the file
    :return: the file path to be uploaded to
    """
    return 'user_{0}/avatar/{1}'.format(instance.user.id, filename)