Skip to content

List Final Grades with edx_course_key#5510

Open
annagav wants to merge 2 commits intomasterfrom
ag/final_grade_search
Open

List Final Grades with edx_course_key#5510
annagav wants to merge 2 commits intomasterfrom
ag/final_grade_search

Conversation

@annagav
Copy link
Copy Markdown
Contributor

@annagav annagav commented Apr 28, 2026

What are the relevant tickets?

N/A

Description (What does it do?)

List Final Grades with edx_course_key

How can this be tested?

Go to /admin/

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the FinalGradeAdmin to display specific fields from the related course_run model. However, the use of double-underscore syntax in list_display is not supported by Django and will cause a SystemCheckError. It is recommended to use custom methods to access these related fields and to include list_select_related to prevent N+1 query performance issues.

Comment thread grades/admin.py Outdated
"""Admin for FinalGrade"""
model = models.FinalGrade
list_display = ('id', 'grade', 'user', 'course_run', )
list_display = ('id', 'grade', 'user', 'course_run__edx_course_key', 'course_run__title')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Django's list_display does not support the double-underscore (__) syntax for traversing relationships directly. Using course_run__edx_course_key and course_run__title will result in a SystemCheckError (FieldDoesNotExist). To display fields from a related model, you should define methods on the ModelAdmin class.

Additionally, you should use list_select_related to avoid N+1 query performance issues when displaying these related fields.

    list_display = ('id', 'grade', 'user', 'get_edx_course_key', 'get_course_run_title')
    list_select_related = ('course_run', 'user')

    def get_edx_course_key(self, obj):
        return obj.course_run.edx_course_key
    get_edx_course_key.short_description = 'Edx Course Key'
    get_edx_course_key.admin_order_field = 'course_run__edx_course_key'

    def get_course_run_title(self, obj):
        return obj.course_run.title
    get_course_run_title.short_description = 'Course Run Title'
    get_course_run_title.admin_order_field = 'course_run__title'

@annagav annagav force-pushed the ag/final_grade_search branch from af9128b to 30c1361 Compare April 28, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant