Skip to content

Commit 9efde31

Browse files
kdmccormickclaude
andcommitted
feat: Django admin page for CourseArchiveStatus
Expose the sample plugin's one model in the LMS/CMS admin so operators can inspect and manage records without custom tooling, and so the sample demonstrates the standard ModelAdmin pattern alongside the other plugin interfaces. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 487b76e commit 9efde31

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

  • backend-plugin-sample/src/openedx_plugin_sample
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Django admin configuration for openedx_plugin_sample.
3+
4+
This module demonstrates how to expose plugin models in the Django admin
5+
site provided by Open edX (LMS and CMS each have their own admin under
6+
``/admin/``). Defining a ``ModelAdmin`` for each model gives operators a
7+
ready-made UI to inspect and manage plugin data without needing custom
8+
tooling.
9+
10+
Django Documentation:
11+
- ModelAdmin: https://docs.djangoproject.com/en/stable/ref/contrib/admin/
12+
"""
13+
14+
from django.contrib import admin
15+
16+
from openedx_plugin_sample.models import CourseArchiveStatus
17+
18+
19+
@admin.register(CourseArchiveStatus)
20+
class CourseArchiveStatusAdmin(admin.ModelAdmin):
21+
"""
22+
Admin configuration for the CourseArchiveStatus model.
23+
"""
24+
25+
list_display = (
26+
"course_key",
27+
"user",
28+
"is_archived",
29+
"archive_date",
30+
"updated_at",
31+
)
32+
list_filter = ("is_archived",)
33+
# Search by the related CourseRun's course_key and the user's username/email.
34+
search_fields = (
35+
"course_run__course_key",
36+
"user__username",
37+
"user__email",
38+
)
39+
# FKs use raw id widgets (lookup popup) rather than a <select>, since the
40+
# CourseRun and User tables can have many thousands of rows on a real
41+
# Open edX deployment.
42+
raw_id_fields = ("course_run", "user")
43+
readonly_fields = ("created_at", "updated_at")
44+
ordering = ("-updated_at",)
45+
46+
@admin.display(description="Course key", ordering="course_run__course_key")
47+
def course_key(self, obj: CourseArchiveStatus) -> str:
48+
"""
49+
Show the course's course_key string in list_display.
50+
51+
We never expose CourseRun's internal integer PK in the admin; the
52+
course_key (e.g. "course-v1:edX+DemoX+Demo_Course") is the identifier
53+
operators recognize.
54+
"""
55+
return str(obj.course_run.course_key)

0 commit comments

Comments
 (0)