diff --git a/course_discovery/apps/tagging/admin.py b/course_discovery/apps/tagging/admin.py index 6fb7408f44..369c51bdee 100644 --- a/course_discovery/apps/tagging/admin.py +++ b/course_discovery/apps/tagging/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin from course_discovery.apps.tagging.models import CourseVerticalFilter, SubVerticalFilter, VerticalFilter +from course_discovery.apps.course_metadata.models import Course @admin.register(VerticalFilter) @@ -32,3 +33,11 @@ class CourseVerticalFiltersAdmin(admin.ModelAdmin): list_filter = ('vertical', 'sub_vertical') search_fields = ('course__title', 'vertical__name', 'sub_vertical__name') ordering = ('course__title',) + + def formfield_for_foreignkey(self, db_field, request, **kwargs): + """ + Override the formfield_for_foreignkey method to filter non-draft entriy of courses + """ + if db_field.name == 'course': + kwargs['queryset'] = Course.objects.filter(draft=False) + return super().formfield_for_foreignkey(db_field, request, **kwargs)