Created
January 7, 2012 16:14
-
-
Save Rembane/1575160 to your computer and use it in GitHub Desktop.
Bulk upload image files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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