code: def get_used_media():
      
  
      media = set()
  
      for field in get_file_fields():
          is_null = {
              '%s__isnull' % field.name: True,
          }
          is_empty = {
              '%s' % field.name: '',
          }
  
          storage = field.storage
  
          for value in field.model.objects \
                  .values_list(field.name, flat=True) \
                  .exclude(**is_empty).exclude(**is_null):
              if value not in EMPTY_VALUES:
                  media.add(storage.path(value))
  
      return media
docs: Get media which are still used in models