def fill_files_from_mock(apps, schema_editor): helpers.mkdir_recursive(settings.MEDIA_ROOT) helpers.copy_dir_recursive('mock/manager/properties_0011/file/media', settings.MEDIA_ROOT) try: with open('mock/manager/properties_0011/file/list.json') as f: content = f.read() f.close() except IOError: content = '[]' records = json.loads(content) File = apps.get_model("file", "File") for record in records: file, created = File.objects.get_or_create(src=record['src']) file.comment = record['comment'] file.save()
def fill_from_mock(apps, schema_editor): helpers.mkdir_recursive(settings.MEDIA_ROOT) helpers.copy_dir_recursive(os.path.join('mock', 'file', 'media'), settings.MEDIA_ROOT, remove_if_exists=True) try: with open(os.path.join('mock', 'file', 'list.json')) as f: content = f.read() f.close() except IOError: content = '[]' records = json.loads(content) File = apps.get_model("file", "File") for record in records: file, created = File.objects.get_or_create(pk=record['id'], src=record['src']) file.comment = record['comment'] file.save() helpers.get_thumbnail(record['src'])