title: Django Wizard Form : is it possible to have a search engine for a specific step?
body: <p>I'm struggling with my Django application, to the point of asking my first question on StackOverflow.</p>
  <p>To be short, I have a form where the user (a farmer) allows him to add a plant on a culture.</p>
  <p>It'd be handy if instead of a boring select box, the farmer could just write down a few letters and every related results pop on the screen. The farmer would pick-up the plant and proceed to the next step. Since he had 330 different seeds, it's not just a fancy functionality.</p>
  <p>I'm able to build a &quot;simple&quot; WizardForm, I already have the search engine and my field is populated with a ModelChoiceField()... I feel like I'm so close yet so far :(</p>
  <p>I have also considered that WizardForm might not be the right approach for what I'm doing. But I feel like I'm just missing something.</p>
  <p>Do any of you have any suggestion on it?</p>
  <p>Below, you can read a few extracts from my code. I will try to clean-up the mess and provide you a readable code.</p>
  <pre><code>models.py
  
  '''
  From the model, the only field that interests this question is the second one, id_graine (graine means seed).
  '''
  
  class Lot(models.Model):
      id = models.AutoField(primary_key = True)
      id_graine = models.ForeignKey('Graine', on_delete = models.PROTECT, related_name = 'id_graine', null = True, blank = True)
      nom_culture_incubation = models.ForeignKey('Culture', on_delete = models.PROTECT, related_name = 'nom_culture_incubation', null = True, blank = True)
      nom_culture = models.ForeignKey('Culture', on_delete = models.PROTECT, related_name = 'nom_culture', null = True, blank = True)
      etat_lot = models.CharField('état', choices = EtatLotsChoix.choices, max_length = 50, null = True, blank = True)
      quantite_lot = models.PositiveSmallIntegerField('quantité', null = True, blank = True)
      semis_date = models.DateField('date de semis', null = True, blank = True)
      phase_lunaire_semis = models.CharField('phase lunaire de semis', max_length = 4, blank = True)
      constellation_semis = models.CharField('constellations de semis', max_length = 7, blank = True)
      germination_date = models.DateField('date de germination', null = True, blank = True)
      plantaison_date = models.DateField('date de plantaison', null = True, blank = True)
      phase_lunaire_plantation = models.CharField('phase lunaire de plantation', choices = PhasesLunairesChoix.choices, max_length = 4, blank = True)
      constellation_plantation = models.CharField('constellations de plantation', choices = ConstellationChoix.choices, max_length = 7, blank = True)
      culture_introduction_date = models.DateField('date d\'introduction', null = True, blank = True)
      floraison_date = models.DateField('date de floraison', null = True, blank = True)
      recolte_date = models.DateField('date de récolte', null = True, blank = True)
  
      def __int__(self):
          return self.id
  
      class Meta:
          verbose_name = 'Lot'
          verbose_name_plural = 'Lots'
  </code></pre>
  <pre><code>views.py
  
  class AjoutLotWizard(SessionWizardView):
      template_name = 'wizardforms/ajout_lot_seme.html'
  
      def get_context_data(self, form, **kwargs):
  
          '''
          I told you that I was able to provide choices through a ModelChoiceField. But this approach 
          didn't pay off well. I also had a successful attempt by providing a context to the template
          with those informations.
          '''
  
          if self.request.GET.get('search_value') != None:
  
              search_value = self.request.GET.get('search_value')
  
              search_results = Graine.objects.filter(espece_graine__contains = search_value)
  
              context = super(AjoutLotWizard, self).get_context_data(form = form, **kwargs)
  
              if (self.steps.current == '0') &amp; (self.request.GET.get('search_value') != None):
                  context.update({'search_results': search_results})
  
                  return context
              else:
  
                  return context
  </code></pre>
  <p>Within views.py, I also tried to pass data with get_form_kwargs(), get_form_step_data(), overwrite get() with a custom attribute.</p>
  <p>The approach with get_form_kwargs was promising once I was able to store my values in variables inside unfortunately, I couldn't manipulate them as I wanted within the WizardView.</p>
  <pre><code>forms.py
  
  class AddLotSemeStep1(forms.ModelForm):
  
      '''
      This file might not be accurate. I did a mess on that part by rewriting __init__().
      But from what I remember, there wasn't more within the form when I use get_context_data
      to provide choices anyway with the template.
      '''
  
      class Meta:
          model = Lot
          fields = ['id_graine']
          labels = {
              'id_graine': 'Graine'
          }
          widgets = {
              'id_graine': forms.RadioSelect()
          }
  </code></pre>
  <pre><code>template.html
  
  {% load static %}
  {% load i18n %}
  {% block content %}
      {% include 'components/_base.html' %}
      &lt;main class=&quot;wizard-form-main&quot;&gt;
          &lt;h2&gt;Ajout de lot semé - le 1&lt;/h2&gt;
          &lt;p&gt;Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}&lt;/p&gt;
  
          &lt;form action=&quot;&quot; method=&quot;GET&quot; name=&quot;searchbar&quot;&gt;
              &lt;input type=&quot;text&quot; name=&quot;search_value&quot;&gt;
              &lt;button type=&quot;submit&quot;&gt;Rechercher&lt;/button&gt;
          &lt;/form&gt;
  
          &lt;form action = &quot;&quot; method = &quot;POST&quot; name=&quot;wizardform&quot;&gt;
          {% csrf_token %}
              &lt;table&gt;
                  {{ wizard.management_form }}
                  {% if wizard.form %}
                      {{ wizard.form.management_form }}
                      {{ wizard.form }}
                  {% else %}
                      {% for result in search_results %}
                          &lt;p&gt;
                              &lt;label&gt;
                                  &lt;input type=&quot;radio&quot; name=&quot;chope_id&quot; value=&quot;{{result.id}}&quot;&gt;
                                  {{result.espece_graine}} {{result.variete_graine}}, ({{result.provenance}} {{result.annee_de_recolte|cut:&quot;.0&quot;}})
                              &lt;/label&gt;
                              &lt;input type=&quot;submit&quot; value=&quot;Ajouter cette graine&quot;&gt;
                          &lt;/p&gt;
                      {% endfor %}
                  {% endif %}
              &lt;/table&gt;
              {% if wizard.steps.prev %}
              &lt;!--&lt;button name=&quot;wizard_goto_step&quot; type=&quot;submit&quot; value=&quot;{{ wizard.steps.first }}&quot;&gt;{% trans &quot;first step&quot; %}&lt;/button&gt;--&gt;
              &lt;button name=&quot;wizard_goto_step&quot; type=&quot;submit&quot; value=&quot;{{ wizard.steps.prev }}&quot;&gt;{% trans &quot;prev step&quot; %}&lt;/button&gt;
              {% endif %}
              &lt;input type = &quot;submit&quot; value = &quot;étape suivante&quot;&gt;
          &lt;/form&gt;
      &lt;/main&gt;
  {% endblock %}
  </code></pre>
  <p>Thank you for your attention if you managed to read all of it !</p>