title: Django register ModelForm with Model
body: <p>I have several MyModels, all derived from the same MyBaseModel, and for each model there is also a MyModelForm derived from MyModelBaseForm.
  Given a MyModelForm, I can access the related model through MyModelForm._meta.model.
  What would be the easiest way to do the reverse: given a MyModel, get the corresponding MyModelForm?</p>
  
  <p>The reason is I want to use duck typing in a view:</p>
  
  <pre><code>from django.db import models
  
  def edit_view(request, my_model_name, pk=None):
      my_model = my_model_registry[my_model_name]
      instance = get_object_or_404(my_model, pk=pk) if pk else None
      my_model_form = my_model._meta.modelform 
      # or my_model_form = my_model_form_registry[my_model]
      form = my_model_form(request.POST or None, instance=instance)
      if form.is_valid():
          instance = form.save()
          return HttpResponseRedirect(instance.get_absolute_url())
      return render(request, 'my_template', {'form': form, 'instance': instance})
  
  my_model_registry = dict( (Model._meta.verbose_name, Model) for Model in
                            models.get_models() if issubclass(Model, MyBaseModel)
                            )
  </code></pre>
  
  <p>The ideal solution would be to have a dictionary <code>my_model_form_registry[my_model]</code> so that I can look up the form just like I do with the model. I know I can do this manually, by explicitly setting</p>
  
  <pre><code>my_model_form_registry[MyModelForm._meta.model] = MyModelForm
  </code></pre>
  
  <p>after each MyModelForm definition, but in the spirit of DRY, I would like to do this once for the ModelBaseForm and have it executed automatically for all derived models.</p>
  
  <p>Metaclasses can do this, but I can not get this to work because model.ModelForm already has a special metaclass.</p>
  
  <p>Another option would be if there were an equivalent to <code>models.get_models</code>, but for modelforms. Does that exist?</p>