title: How to get Django form field from model field?
body: <p>I'd like to create a form that includes fields from two separate models, along with some other regular (non-model) fields. The form will create an instance of each model. I don't <em>think</em> I can use inline formsets for this, since I don't want to include all the fields from both models.</p>
  
  <p>I'd like to create the form field without hard-coding the type of the model fields.</p>
  
  <p>I know I can get a form field from a model field using <code>model_field.formfield()</code>. But how can I get the specific model field?</p>
  
  <p>My first solution:</p>
  
  <pre><code>def get_fields(model_class):
      fields = {}
      for f in model_class._meta.fields:
          fields[f.name] = f
  
  class MyForm(forms.Form):
      foo_name = get_fields(Foo)['name'].formfield()
      bar_name = get_fields(Bar)['name'].formfield()
      other_field = ...
  </code></pre>
  
  <p>Is there an equivalent of <code>get_fields</code> already? Is this a bad idea? I'm uncomfortable relying on the model <code>_meta</code> attribute. Or am I going about this the completely wrong way?</p>