Skip to content

Commit

Permalink
feat: add logic to filter non-draft entry of courses
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Jan 15, 2025
1 parent fd11a49 commit 2fdbe46
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions course_discovery/apps/tagging/admin.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit 2fdbe46

Please sign in to comment.