Skip to content

Commit 9e40eb7

Browse files
Set _state.adding when cloning models (#108)
The [docs](https://docs.djangoproject.com/en/4.2/topics/db/queries/#copying-model-instances) for cloning a model instance say to also set this attribute to `True`. This PR does just that.
1 parent 85dbe0c commit 9e40eb7

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

tin/apps/courses/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def import_from_selected_course(request, course_id, other_course_id):
186186
for folder in form.cleaned_data["folders"]:
187187
assignments = list(folder.assignments.all())
188188
folder.pk = None
189+
folder._state.adding = True
189190
folder.course = course
190191
folder.save()
191192
for assignment in assignments:
@@ -201,6 +202,7 @@ def import_from_selected_course(request, course_id, other_course_id):
201202

202203
# Save as new
203204
assignment.pk = None
205+
assignment._state.adding = True
204206

205207
# Update course, folder, assigned date, and grader file
206208
assignment.course = course

0 commit comments

Comments
 (0)