On Mon, Jun 2, 2008 at 10:06 AM, David.D <[EMAIL PROTECTED]> wrote:

>
> In my "products" app:
>
> models.py
> ========
>
> class ModelA(models.Model):
>    ...
>
> class ModelB(models.Model):
>    ...
>
> class ModelC(models.Model):
>    ...
> ...
> class ModelAForm(ModelForm):
>    class Meta:
>        model = ModelA
>
> class ModelBForm(ModelForm):
>    class Meta:
>        model = ModelB
>
> class ModelCForm(ModelForm):
>    class Meta:
>        model = ModelC
> ...
>
>
> views.py
> ======
> def model_form(request, model_name):
>    form_class = __import__('products.models.%sForm'%model_name)
>    form = form_class()
>    ...
>
> model_name is a string


This __import__ is equivalent to "import
products.models.your_model_form_name" which is not what you want.  You want
"from products.models import your_model_form_name".  For that, your
__import__ needs to be of the form:

form_class = __import__('products.models', {} , {}, [model_name])

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to