Add trans and migration
This commit is contained in:
parent
c833dc06d9
commit
a230441862
5 changed files with 220 additions and 153 deletions
29
judge/migrations/0193_remove_old_course_problems.py
Normal file
29
judge/migrations/0193_remove_old_course_problems.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Generated by Django 3.2.18 on 2024-09-03 14:33
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def migrate_problems_to_courselessonproblem(apps, schema_editor):
|
||||
CourseLesson = apps.get_model("judge", "CourseLesson")
|
||||
CourseLessonProblem = apps.get_model("judge", "CourseLessonProblem")
|
||||
|
||||
for lesson in CourseLesson.objects.all():
|
||||
for problem in lesson.problems.all():
|
||||
CourseLessonProblem.objects.create(
|
||||
lesson=lesson, problem=problem, order=1, score=1
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("judge", "0192_course_lesson_problem"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_problems_to_courselessonproblem),
|
||||
migrations.RemoveField(
|
||||
model_name="courselesson",
|
||||
name="problems",
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue