inject instance into formset

I’m not sure if I phrased my question correctly. What I would like to do is create a formset where one of the fields is a ForeignKey. When the form is created, I want it to iterate through the foreignkey and inject them into the form.

For the example below I want to input a score for each student. I don’t want to pick each student, I want the students to be pre-populated and non-editable.

class Student(models.Model):
    classroom = models.ForeignKey(Classroom, on_delete=models.CASCADE)

class ScaleGrade(models.Model):
    score = models.IntegerField()
    student = models.ForeignKey(Student, on_delete=models.CASCADE)
    time_created = models.DateField(auto_now_add=True)

def addgrades(request):
    students = Student.objects.all()
    context = {'students': students}

    if request.method == 'POST':
        formset = ScaleGradeFormSet(request.POST)

        if formset.is_valid():
            return redirect(reverse_lazy("assesslist"))

        formset = ScaleGradeFormSet(queryset=students)
        context['formset'] = formset
        return render(request, "gradebook/grade_form.html", context)

class ScaleGradeForm(ModelForm):
    class Meta:
        model = ScaleGrade
        exclude = ()

ScaleGradeFormSet = modelformset_factory(
    ScaleGrade, fields=('score', 'student',))


  <h1>Add new grades</h1>
  <form id="form-container" method="POST">
	  {% csrf_token %}
	  {{ formset.management_form }}
	  {% for form in formset %}
	  <div class="grade-form">
	  {{ form.as_p }}
	  {% endfor %}
	  <button type="submit">Create Grades</button>

See the docs for Passing custom parameters to formset forms. In general, you’ll want to assign a different student to each instance of the form, and mark that field as either read-only or disabled. (In this case, I would tend to suggest disabled.)

This topic was also discussed here: Pass different parameters to each form in formset. (The author of the first comment also makes reference to:

Thanks. I have been working through the docs the past day or two but I find them and figured I needed extra help. The topic that you linked looks very helpful, along with the datalowe link.