title: Django formset - how to give a different queryset for each form within the modelformset
body: <p>I have a form for a Model - ClinicallyReportedSample, which links to a Sample model. </p>
  
  <p>I am trying to create a formset for ClinicallyReportedSample where, based on a queryset of Sample, a specific amount of forms are displayed so that the user can add data.</p>
  
  <p>Currently, the Sample model has entries, but the ClinicallyReportedSample model is completely empty:</p>
  
  <p>models:</p>
  
  <pre><code>class Sample(models.Model):
  
      request_number = models.PositiveIntegerField()
      year = models.PositiveIntegerField()
  
  
      class Meta:
          db_table = "sample"
          unique_together = (('request_number', 'year'),)
  
      def __str__(self):
          return("%s/%s" %(self.request_number, self.year))
  
  
  
  class ClinicallyReportedSample(models.Model):
  
      sample_id = models.ForeignKey(Sample,
                                  on_delete=models.CASCADE,
                                  db_column='sample_id')
  
  
      reported = models.BooleanField(default=False)
      evidence = models.TextField(null=True, blank=True)
  
      ... other fields ...
  
      class Meta:
          db_table = "clinically_reported_sample"
          unique_together = (('sample_id'),)
  
      def __str__(self):
          clinically_reported_sample = str(self.sample_id)
          return(clinically_reported_sample)
  </code></pre>
  
  <p>I want ClinicallyReportedSample model forms, within a formset, that relate to a queryset of Sample model.</p>
  
  <p>For example, Sample objects with pk 1, 2 and 3:</p>
  
  <p>forms.py:</p>
  
  <pre><code>class BaseCRSFormSet(BaseModelFormSet):
      def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
          # self.queryset = ClinicallyReportedVariant.objects.none()
  
  
  class CRSForm(forms.ModelForm):
  
      class Meta:
          model = ClinicallyReportedSample
          fields = ('sample_id', 'evidence',)
  
      def __init__(self, *args, **kwargs):
          super(CRSForm, self).__init__(*args, **kwargs)
  </code></pre>
  
  <p>So I try to do this using queryset in my formset</p>
  
  <p>views.py:</p>
  
  <pre><code>def get(self, request, *args, **kwargs):
  
  
      sample_obj = Sample.objects.filter(id__in=[1, 2, 3])
  
      formset = modelformset_factory(
                  ClinicallyReportedSample,
                  form=self.crsform,
                  formset=BaseCRSFormSet,
                  extra=3,
              )
  
  
      formset = formset(queryset=sample_obj)
  </code></pre>
  
  <p>but this displays as three forms, with ALL Sample objects, the queryset does not work. Is this the correct way to go about this?</p>