Skip to content

Commit

Permalink
feat: add external course id fields and enhance admin models (#3006)
Browse files Browse the repository at this point in the history
* feat: add external course id fields and enhance admin models

* feat: add migration

* feat: add blank true
  • Loading branch information
asadali145 committed Jun 11, 2024
1 parent dd5b14d commit 1e4e48a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion courses/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ class CourseRunAdmin(TimestampedModelAdmin):
"title",
"courseware_id",
"run_tag",
"get_course_platform",
"start_date",
"end_date",
"enrollment_start",
)
list_filter = ["live", "course"]
list_filter = ["live", "course__platform", "course"]

formfield_overrides = {
models.CharField: {"widget": TextInput(attrs={"size": "80"})}
Expand All @@ -109,6 +110,13 @@ def get_changeform_initial_data(self, request):
initial["end_date"] = start_date + timedelta(days=1)
return initial

@admin.display(description="Platform")
def get_course_platform(self, instance):
"""
Returns the course platform.
"""
return instance.course.platform


@admin.register(ProgramEnrollment)
class ProgramEnrollmentAdmin(AuditableModelAdmin):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.13 on 2024-06-07 10:29

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("courses", "0038_alter_certificate_page_revision"),
]

operations = [
migrations.AddField(
model_name="course",
name="external_course_id",
field=models.CharField(blank=True, default="", max_length=255),
),
migrations.AddField(
model_name="courserun",
name="external_course_run_id",
field=models.CharField(blank=True, default="", max_length=255),
),
]
2 changes: 2 additions & 0 deletions courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ class Course(TimestampedModel, PageProperties, ValidateOnSaveMixin):
)
live = models.BooleanField(default=False)
is_external = models.BooleanField(default=False)
external_course_id = models.CharField(max_length=255, blank=True, default="")
platform = models.ForeignKey(
Platform, on_delete=models.PROTECT, null=False, blank=False
)
Expand Down Expand Up @@ -608,6 +609,7 @@ class CourseRun(TimestampedModel):
help_text="A string that identifies the set of runs that this run belongs to (example: 'R2')",
)
courseware_url_path = models.CharField(max_length=500, blank=True, null=True) # noqa: DJ001
external_course_run_id = models.CharField(max_length=255, blank=True, default="")
start_date = models.DateTimeField(null=True, blank=True, db_index=True)
end_date = models.DateTimeField(null=True, blank=True, db_index=True)
enrollment_start = models.DateTimeField(null=True, blank=True, db_index=True)
Expand Down

0 comments on commit 1e4e48a

Please sign in to comment.