i'm trying to do some instantiation of models, based on run time
parameters. i'm new to django/python so not sure the term, but the
relative java term is reflection.

for example, if i have a model, in my django models.py:

class Foo(models.Model):
    name = models.CharField(max_length=20)

now in some views.py code, i'm given, say some xml that defines a new
Foo object, so i want to dynamically create a new Foo object and save
it.  <xml><Foo><name>bar</name></Foo></xml>

i've tried a few things below, but namely, what i'm trying to do is
parse the xml, see that i need to create "Foo" and set it's name to
bar:

tag = "Foo"
key = "name"
value = "bar"

 _temp = __import__('project.test.models', globals(), locals(),
['Foo'], -1)
 createobj = getattr(_temp, tag)
setattr(createobj, key, value)
createobj.save()

i'm getting unbound method on save, and tried various ways to save.
but i'm thinking it is in the class instantiation where the problem
is.

thanks!

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to