Created
August 21, 2013 12:55
-
-
Save tianweidut/6294105 to your computer and use it in GitHub Desktop.
love xinxin
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
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