Skip to content

Commit

Permalink
Only show projects for active course
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebrownlee committed Feb 26, 2024
1 parent fd488e9 commit 262a1c8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LearningAPI/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django import forms
from django.contrib import admin

# Register your models here.
Expand Down Expand Up @@ -51,9 +52,23 @@ class BookAdmin(admin.ModelAdmin):
"""For assigning students to cohorts"""
list_display = ('name', 'course',)


class StudentProjectForm(forms.ModelForm):
class Meta:
model = StudentProject
fields = '__all__'

def __init__(self, *args, **kwargs):
super(StudentProjectForm, self).__init__(*args, **kwargs)
# Assuming Project model has a relation to Book and then to Course
# Adjust 'project__book__course__active=True' to match your model's relationships
self.fields['project'].queryset = Project.objects.filter(book__course__active=True)


@admin.register(StudentProject)
class StudentProjectAdmin(admin.ModelAdmin):
"""For assigning students to cohorts"""
form = StudentProjectForm
list_display = ('student', 'project',)
search_fields = ["student__user__last_name"]
search_help_text = "Search by last name"
Expand Down

0 comments on commit 262a1c8

Please sign in to comment.