title: How to pass a value in a Django drop down from a ModelForm
body: <p>I want to display different fonts for users from a drop-down. The drop-down derives its values from the model which has <strong>choices</strong> option. The problem is when a certain font is chosen, it saves well in the database but the “value” is not caught.</p>
  <p>Here is the flow of the project:</p>
  <p><strong>Model:</strong></p>
  <pre><code>class Company(models.Model): 
      name = models.CharField(max_length=100, null=True, blank=True
      first_font = models.CharField(max_length=100, choices=header_font, blank=True, null=True)
      second_font = models.CharField(max_length=100, choices=body_font, blank=True, null=True)
  
      class Meta:
          verbose_name_plural = &quot;Companies&quot;
      
      def __str__(self):
          return self.name
  </code></pre>
  <p><strong>Forms.py</strong></p>
  <pre><code>class CompanyForm(forms.ModelForm):
  
      def __init__(self, *args, user=None,  **kwargs):
          super(CompanyForm, self).__init__(*args, **kwargs)
  
          self.fields['first_font'].widget.attrs = {'class': 'select',}
          self.fields['second_font'].widget.attrs = {'class': 'select',}
      
      class Meta:
          model = Company
          fields = ('first_font', 'second_font',)
  </code></pre>
  <p><strong>Template output:</strong></p>
  <p>I have used <strong>HTMX</strong> to take the value of the drop-down and pass it to a partial template so that it can be inserted in a class and return a well-formatted sentence with the font applied.</p>
  <pre><code>&lt;form action=&quot;&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;
    &lt;div class=&quot;column is-4&quot;&gt;
     &lt;h2&gt;Choose fonts for documents&lt;/h2&gt;
    &lt;div class=&quot;field&quot;&gt;
     &lt;label class=&quot;label&quot;&gt;Heading Font&lt;/label&gt;
     
    &lt;div class=&quot;select is-fullwidth&quot;
    name = &quot;heading_font&quot;
    hx-get=&quot;{% url 'main_font' %}&quot;
    hx-target=&quot;#main-font&quot;
    hx-trigger=&quot;change&quot;
    &gt;
    {{ form.first_font }}
  
   &lt;/div&gt;
    &lt;div id=&quot;main-font&quot;&gt;
      &lt;p&gt;This is your font&lt;/p&gt;
   &lt;/div&gt;
   &lt;/div&gt;
   &lt;div class=&quot;field&quot;&gt;
   &lt;label class=&quot;label&quot;&gt;Body Font&lt;/label&gt;
  
   &lt;div class=&quot;select is-fullwidth&quot;
    name = &quot;body_font&quot;
    hx-get=&quot;{% url 'secondary_font' %}&quot;
    hx-target=&quot;#secondary-font&quot;
    hx-trigger=&quot;change&quot;
    &gt;
    {{form.second_font }}
    
   &lt;/div&gt;
  
   &lt;div id=&quot;secondary-font&quot;&gt;
    &lt;p&gt;This is your font&lt;/p&gt;
   &lt;/div&gt;
   &lt;/div&gt;
  
   &lt;/div&gt;
   &lt;/form&gt;
  </code></pre>
  <p><strong>Here is the partial template example for Second Font:</strong></p>
  <pre><code>&lt;p class=&quot;second-display&quot;&gt;
      This is your main body font
   &lt;p&gt;{{chosen}}&lt;/p&gt;
   &lt;/p&gt;
  
   &lt;style&gt;
   .second-display {
      font-family: {{chosen}};
      font-size: 30px;
      font-style: bold;
      margin-top: 20px;
      margin-bottom: 20px;
    }
    &lt;/style&gt;
  </code></pre>
  <p>And finally the two partial views that will return the above template, for secondary_font. The issue is the value that is supposed to be stored in the “chosen” variable is not getting caught and not sent to the above partial. How do I get the right “value”?</p>
  <pre><code>@login_required(login_url='login')
  def main_font(request):
      chosen = request.GET.get('heading_font')
      return render(request, 'company/first-font.html', {'chosen': chosen})
  
  @login_required(login_url='login')
  def secondary_font(request):
      chosen = request.GET.get('body_font')
      return render(request, 'company/second-font.html', {'chosen': chosen})
  </code></pre>
  <p>I will appreciate any help and pointers.</p>