Sunday, June 30, 2013

Re: Get Form from string?

Sorry but I forgot show my form:

This is my Form:

class MyForm(ModelForm):      class Meta:          form = 'my_form'          model = MyModel          exclude = ('country', 'region')
My all form in subclass Meta contains variable 'form'. This is name of my form. The definition get_form search in all included form one string name, and return this Form.

url(r'^/some-url/(?P<form_name>[a-zA-Z0-9]+)/', 'my_view', name='my-wiev'),
and view:

def my_view(request, form_name):      form = get_form(my_form)      response = {}      response['my_form'] = form      return render_to_response('request/window.html', response)

W dniu piątek, 28 czerwca 2013 22:09:41 UTC+2 użytkownik MacVictor napisał:
get the model by string i use:

from django.db.models.loading import get_model
def get_model(self, app_label, model_name, seed_cache=True):

how to get ModelForm by string?

i try used:

modelforms = forms.ModelForm.__subclasses__()

def get_form(form):
        for model_form in modelforms:
                if model_form.Meta.form == form:
                    return model_form
            except AttributeError:
    except IndexError:
        print "Does not exist Model Forms for the object"

but I must import the form in which I will seek appropriate by name!

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment