Skip to content

Instantly share code, notes, and snippets.

@tianweidut
Created August 21, 2013 12:55
Show Gist options
  • Save tianweidut/6294105 to your computer and use it in GitHub Desktop.
Save tianweidut/6294105 to your computer and use it in GitHub Desktop.
love xinxin
from django.core.files import File
def importFiles(record, preset):
ret = {'xml': record[XML], 'pic': record[PIC], 'js': record[JS]}
fs = FileStorage()
for key, value in ret.items():
if os.path.isfile(value) is True:
with File(open(value, 'r')) as f:
fs.file_name = os.path.basename(value).split('.')[0]
fs.mapping_preset_id = preset
fs.file_type = FileTypeDict.objects.get(category=key)
fs.file_obj = f
fs.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment