Внешний ключ Django-фильтра не может попасть в выпадающий список

filter.py

class StudentFilter(django_filters.FilterSet):
    # SchoolName = django_filters.ModelMultipleChoiceFilter(queryset=MasterSchool.objects.all())
    class Meta:
        model = Student
        fields = ['StudentId', 'School', 'Division']

Здесь я попробовал School__SchoolName, но он не показывает выпадающий список.

model.py

class MasterSchool(models.Model):
    SchoolName=models.CharField(max_length=100, null=False, blank=False, unique=True)
    Active = models.BooleanField(default=True)

    class Meta:
        db_table='master_schools'

class MasterDivision(models.Model):
    DivisionName=models.CharField(max_length=100, null=False, blank=False, unique=True)
    Active = models.BooleanField(default=True)


    class Meta:
        db_table='master_divisions'
class Student(models.Model):
    StudentId=models.CharField(max_length=20, null=True, blank=True)
    StudentName=models.CharField(max_length=100, null=False, blank=False)
    Phone = models.CharField(verbose_name="Phone number", null=True, blank=True, max_length=10, validators=[validate_digit_length], default='1234567890')
    School = models.ForeignKey(MasterSchool, on_delete=models.CASCADE, null=True, blank=True, db_column='SchoolId')
    Division = models.ForeignKey(MasterDivision, on_delete=models.CASCADE, null=True, blank=True, db_column='DivisionId')
    StudentPhoto= models.ImageField( null=True, blank=True, default="default.png", upload_to='studentphoto/resgistred_photos/')
    PhotoMatrix=models.CharField(max_length=100, null=True, blank=True)
    
    class Meta:
        db_table='students'

        ordering = ['id']

view.py

def StudentDetail(request):
    if(request.session.has_key('uid')):
        stud = Student.objects.all()
        
        schools = MasterSchool.objects.all()

        divisions = MasterDivision.objects.all()
        
        tableFilter = StudentFilter(request.GET, queryset=stud)
        students = tableFilter.qs
        page = request.GET.get('page', 1)
        paginator = Paginator(students, settings.PAGE_LIMIT)
        
        try:
            student_list = paginator.page(page)
        except PageNotAnInteger:
            student_list = paginator.page(1)
        except EmptyPage:
            student_list = paginator.page(paginator.num_pages)

    context = {
        'student_list':student_list ,
        'students': students, 
        'tableFilter':tableFilter,
        'root_url':settings.ROOT_URL,
        'schools': schools, 
        'divisions': divisions  }
    return render(request, 'web_api/student_details.html', context)

html

 <form method="get" class="forms-sample" autocomplete="off" >
           
                      {{tableFilter.form}}

                      <button class="btn btn-primary" type="submit"><i class="fa fa-search" aria-hidden="true"></i> Search</button>
                     
                    </form>
           
                      <div class="table-sorter-wrapper col-lg-12 table-responsive">
                        <table id="sortable-table-2" class="table table-striped">
                          <thead>
                            <tr>
                              <th>ID</th>
                              <th>Student Name</th>
                              <th>School Name</th>
                              <th>Division</th>
                              <th>Image</th>
                              <th>Option</th>
                            </tr>
                          </thead>
                          <tbody>
                            {% for student in student_list %}
                            <tr>
                              <td>
                                <span>{{student.StudentId}}</span>
                              </td>
                              <td>
                                <span>{{student.StudentName}}</span>
                              </td>
                              <td>
                                <span>{{student.School.SchoolName}}</span>
                              </td>
                              <td>
                                <span>{{student.Division.DivisionName}}</span>
                              </td>
                       {% endfor %}
                          </tbody>
                        </table>
                      </div>

заранее спасибо Я использовал {{tablefilter.form}} но хочу изменить его в соответствии с темой. я использовал его

<label for="id_StudentId">
<input type="text" name="StudentId" id="id_StudentId" style="color: rgb(151, 160, 163);" aria-controls="order-listing" class="form-control" placeholder="Student Id" autocomplete="off"></label>
                      
                      <label for="id_School">
                      <select name="School" for="id_School" style="color: rgb(151, 160, 163);" class="form-control" >
                        <option value="none" selected>Select School</option>
                        {% for school in schools %}
                        <option value='{{school.id}}'>{{school.SchoolName}}</option>
                        {% endfor %}
                      
                        </select>
                        </label>
                      
                      <label for="id_Division">
                      <select name="Division" id="id_Division" style="color: rgb(151, 160, 163);" class="form-control" >
                        <option value>Select Division</option>
                        {% for division in divisions %}
                        <option value='{{division.id}}'>{{division.DivisionName}}</option>
                        {% endfor %}
                       
                      </select>
                      </label> -->

Я хочу отобразить внешний ключ в виде выпадающего списка, также фильтр должен сохранять название школы после субмитинга и фильтровать по нему деление. как показать выбранное значение и выполнить двойную фильтрацию данных

Вернуться на верх