Created
November 4, 2015 17:29
-
-
Save samirbr/f5058b774fefc539c576 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def copy(o, replacements, exclude): | |
| d = model_to_dict(o) | |
| for key in exclude: | |
| d.pop(key) | |
| for key in replacements.keys(): | |
| d[key] = replacements[key] | |
| obj = o.__class__.objects.create(**d) | |
| return obj | |
| trans = { | |
| 'options': {}, | |
| 'questions': {}, | |
| 'rules': {}, | |
| 'form': {}, | |
| } | |
| form = copy(Form.objects.get(id=form_id, deleted=False)) | |
| for question in Question.objects.filter(parent_id=form_id, deleted=False): | |
| q = copy(question, { | |
| 'parent_id': form.id | |
| }, ['id']) | |
| trans['questions'][question.id] = q.id | |
| for option in old_q.get_options(): | |
| o = copy(option, { | |
| 'question_id': q.id | |
| }, [ 'id' ]) | |
| trans['options'][option.id] = o.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment