title: Django: How can I change the design of a foreign key when using forms.py?
body: <p>This is my patient model and forms:</p>
  <pre><code>class Patient(models.Model):
      def __str__(self):
          return f&quot;{self.first_name} {self.last_name}&quot;
      doctor = models.ForeignKey(User, on_delete=models.CASCADE)
      first_name = models.CharField(max_length=100)
      last_name = models.CharField(max_length=100)
      sex = models.CharField(max_length=20)
      phone = models.IntegerField()
      birth_date = models.DateField()
  
  class PatientForm(forms.ModelForm):
      BIRTH_YEAR_CHOICES = []
      for years in range(1900,2021):
          BIRTH_YEAR_CHOICES.append(str(years))
      sex_choice = [('1', 'Homme'), ('2', 'Femme')]
      sex = forms.ChoiceField(widget=forms.Select(attrs={'class':'form-control'}), choices=sex_choice)
      doctor = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}),queryset=Patient.objects.all())
      first_name = forms.CharField(widget= forms.TextInput(attrs={'class':'form-control'}))
      last_name = forms.CharField(widget= forms.TextInput(attrs={'class':'form-control'}))
      phone = forms.CharField(widget= forms.TextInput(attrs={'class':'form-control'}))
      birth_date = forms.DateField(widget=forms.SelectDateWidget(years=BIRTH_YEAR_CHOICES,attrs={'class': 'form-control'}))
  
      class Meta:
          model = Patient
          fields = '__all__'
  
      def __init__(self, *args, **kwargs):
          super(PatientForm, self).__init__(*args, **kwargs)
          self.fields['birth_date'].input_formats = ('%Y-%m-%d')
  </code></pre>
  <p>And this register.html:</p>
  <pre><code>&lt;form method=&quot;POST&quot;&gt;{% csrf_token %}
      &lt;div class=&quot;input-group&quot;&gt;
          &lt;span class=&quot;input-group-text&quot;&gt;Prénom:&lt;/span&gt;
          {{form.first_name}}
      &lt;/div&gt;
      &lt;div class=&quot;input-group&quot;&gt;
          &lt;span class=&quot;input-group-text&quot;&gt;Nom:&lt;/span&gt;
          {{form.last_name}}
      &lt;/div&gt;
      &lt;div class=&quot;input-group&quot;&gt;
          &lt;span class=&quot;input-group-text&quot;&gt;Sex&lt;/span&gt;
          {{form.sex}}
      &lt;/div&gt;
      &lt;div class=&quot;input-group&quot;&gt;
          &lt;span class=&quot;input-group-text&quot;&gt;Telephone&lt;/span&gt;
          {{form.phone}}
      &lt;/div&gt;
      &lt;div class=&quot;input-group&quot;&gt;
          &lt;span class=&quot;input-group-text&quot;&gt;Date de naissance&lt;/span&gt;
          {{form.birth_date}}
      &lt;/div&gt;
      &lt;div class=&quot;input-group&quot;&gt;
          &lt;span class=&quot;input-group-text&quot;&gt;Docteur&lt;/span&gt;
          &lt;select name=&quot;doctor_choice&quot;&gt;
              {% for doctor in doctors %}
                  &lt;option value=&quot;{{doctor.pk}}&quot;&gt;{{doctor.first_name}} {{doctor.last_name}}&lt;/option&gt;
              {% endfor %}
          &lt;/select&gt;
      &lt;/div&gt;
  </code></pre>
  <p>The attrs={'class':'form-control'} is working at all the fields except the doctor field which is a ForeignKey in Patient model. So when I search about it I found that they use doctor = forms.ModelChoiceField but still dosen't work and 'class':'form-control' isn't working yet</p>