Skip to content

Instantly share code, notes, and snippets.

@Rembane
Created January 7, 2012 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rembane/1575160 to your computer and use it in GitHub Desktop.
Save Rembane/1575160 to your computer and use it in GitHub Desktop.
Bulk upload image files
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.core.management import setup_environ
from <project_name> import settings
import os, os.path, sys
setup_environ(settings)
sys.path.append('/the/path/where/the/apps/are')
from app.models import Image
startpath = sys.argv[1]
for (dirpath, dirnames, filenames) in os.walk(startpath):
for fn in filenames:
if '.jpg' in fn or '.png' in fn or '.gif' in fn:
img = Image(image=open(os.path.join(dirpath, fn), 'rb'))
img.save()
# Typ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment