Skip to content

Commit

Permalink
fix: added unique_together constraint on learner pathway course and
Browse files Browse the repository at this point in the history
program models
  • Loading branch information
muhammad-ammar committed Jan 19, 2022
1 parent 7c7e9e8 commit 07a0dc9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 0 additions & 2 deletions course_discovery/apps/learner_pathway/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class LearnerPathwayProgramInline(admin.TabularInline):
model = LearnerPathwayProgram
extra = 0
autocomplete_fields = ('program', )
classes = ('collapse',)
readonly_fields = ('estimated_completion_time',)

def estimated_completion_time(self, pathway_program):
Expand All @@ -27,7 +26,6 @@ class LearnerPathwayCourseInline(admin.TabularInline):
model = LearnerPathwayCourse
extra = 0
autocomplete_fields = ('course', )
classes = ('collapse',)
readonly_fields = ('estimated_completion_time',)

def estimated_completion_time(self, pathway_course):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.10 on 2022-01-19 13:38

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('course_metadata', '0267_remove_course_slug'),
('learner_pathway', '0003_auto_20220119_0726'),
]

operations = [
migrations.AlterUniqueTogether(
name='learnerpathwaycourse',
unique_together={('step', 'course')},
),
migrations.AlterUniqueTogether(
name='learnerpathwayprogram',
unique_together={('step', 'program')},
),
]
10 changes: 10 additions & 0 deletions course_discovery/apps/learner_pathway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ class LearnerPathwayCourse(LearnerPathwayNode):

course = models.ForeignKey(Course, on_delete=models.CASCADE, related_name='learner_pathway_courses')

class Meta:
unique_together = (
('step', 'course'),
)

def get_estimated_time_of_completion(self) -> str:
"""
Returns the average estimated work hours to complete the course run.
Expand Down Expand Up @@ -230,6 +235,11 @@ class LearnerPathwayProgram(LearnerPathwayNode):

program = models.ForeignKey(Program, on_delete=models.CASCADE, related_name='learner_pathway_programs')

class Meta:
unique_together = (
('step', 'program'),
)

def get_estimated_time_of_completion(self) -> str:
"""
Returns the sum of estimated work hours to complete the course run for all program courses.
Expand Down

0 comments on commit 07a0dc9

Please sign in to comment.