title: Populating a drop-down from Database in Django
body: <p>Hi so basically I am trying to populate a drop-down menu from a database I currently have. This will enable a 'Teacher' to select a 'Student' they input grades for. I am struggling to understand any of the tutorials online due to most of them being for django 1.9 whereas I am using 2.1.</p>
  
  <p>Please if you could help, it would be much appreciated.</p>
  
  <p>Template:</p>
  
  <pre><code>&lt;form action="{% url 'subject1_view' %}" method="post"&gt;
  
      {% csrf_token %}
  
      &lt;div class="form-group row"&gt;
          &lt;label class="col-2 col-form-label" for="information"&gt;Student Name&lt;/label&gt;
          &lt;div class="col-10"&gt;
              &lt;form method="POST"&gt;
                  &lt;select class="form-control"  name="student_name" id="information"&gt;
                      {% for ?? %}
                          &lt;option value="{{ ?? }}"&gt;{{ ?? }}&lt;/option&gt;
                      {% endfor %}
                  &lt;/select&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>URLs:</p>
  
  <pre><code>from django.urls import path, include
  from . import views
  
  urlpatterns = [
      path('teacher_login', views.teacher_login, name='teacher_login'),
      path('t_dashboard', views.t_dashboard, name='t_dashboard'),
      path('subject1_view', views.subject1_view, name='subject1_view'),
      path('loguserout', views.loguserout, name='loguserout'),
  ]
  </code></pre>
  
  <p>Views:</p>
  
  <pre><code>def subject1_view(request):
      if request.method == 'POST':
          student_name = (request.POST.get('student_name'))
          current_grade = (request.POST.get('current_grade'))
          previous_grade = (request.POST.get('previous_grade'))
          target_grade = (request.POST.get('target_grade'))
          incomplete_homework = (request.POST.get('incomplete_homework'))
          behaviour_rank = (request.POST.get('behaviour_rank'))
  
          i = Subject1(student_name=student_name, current_grade=current_grade, previous_grade=previous_grade,
                       target_grade=target_grade, incomplete_homework=incomplete_homework, behaviour_rank=behaviour_rank)
          i.save()
  
          return render(request, 'Teacher/dashboard.html')
      else:
          return render(request, 'Teacher/subject1.html')
  </code></pre>
  
  <p>Models:</p>
  
  <pre><code>from django.db import models
  from Student.models import Student
  # Create your models here.
  
  class Subject1(models.Model):
      student_name = models.ForeignKey(Student, on_delete=models.CASCADE)
      current_grade = models.CharField(max_length=2)
      previous_grade = models.CharField(max_length=2)
      target_grade = models.CharField(max_length=2)
      incomplete_homework = models.CharField(max_length=2)
      behaviour_rank = models.CharField(max_length=2)
  
      def __str__(self):
          return self.student_name
  </code></pre>