0

me working on python django school LMS project and facing issue in html dropdown filter. there are 3 fields. teacher name, subject list, and checkbox of classes. If I select class 1 one then that time subject dropdown should be show only related subject but in subject list its showing all subject from database. i will attach a code and required output for reference.

</head>
<body>
    <script>
        function showSuccessPopup() {
            alert("Successfully Submitted");
        }
    </script>
  
    <h2 style="text-align: center;">Assign Subjects and Classes to Teachers</h2><br>
  <div class="container">
  <div class="card">
    <form method="post" onsubmit="showSuccessPopup()">
        {% csrf_token %}
        <div class="form-group">
            <label for="teacher">Teacher:</label>
            <select name="teacher" id="teacher" class="form-control">
                <option>----Select Teacher----</option>

                {% for teacher in teachers %}
                    <option value="{{ teacher.id }}">{{ teacher.first_name }} {{ teacher.last_name }}</option>
                {% endfor %}
            </select>
        </div><br>
        <div class="form-group">
            <label for="subject">Subject:</label>
            <select name="subject" id="subject" class="form-control">
                <option>----Select Subject-----</option>

                {% for subject in subjects %}

                    <option value="{{ subject.id }}">{{ subject.name }}</option>
                {% endfor %}
            </select>
        </div><br>
        <div class="form-group">
            <label for="classes">Classes:</label>
            {% for cls in classes %}
                <div class="form-check">
                    <input type="checkbox" name="classes" value="{{ cls.id }}" class="form-check-input">
                    <label class="form-check-label">{{ cls.classes }}</label>
                </div>
            {% endfor %}
        </div>
        <button type="submit" class="btn btn-primary">Assign</button>
    </form>
</div>
</div>

</body>[dropdown subject](https://i.sstatic.net/Tgkf4GJj.jpg)

expected output in subject dropdown

1
  • {% for subject in subjects %} will display all subjects. You have to make a one-to-many relationship between the Teachers and subjects in the models and filter the subjects according to the teacher.
    – Sophile
    Commented Jun 22, 2024 at 9:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.