On Tue, Dec 23, 2008 at 12:11 PM, dick...@gmail.com <dick...@gmail.com> wrote:
>
> i'm working on a simple concept i'm sure others have solved, but i
> can't get it.
>
> basically, given some <xml> input, i parse it, find which objects to
> create, and do it.
>
> so with a model:
>
> class Foo(models.Model):
>      name = models.CharField(max_length=20)
>
> and input xml of <request><Foo><name>bar</name></Foo></request>
>
> my view would parse that xml, find the Element Request name "Foo",
> instantiate Foo, set the "name" value to bar, and save it.
>
> import myproject.test.models as test_models
> createobj = getattr(test_models, "Foo")
> setattr(createobj, "name", "bar")
> createobj.save()
>
> the current code there above gives me
>
> unbound method save() must be called with Foo instance as first
> argument (got nothing instead)
>
> i've also tried
> save =  getattr(createobj, "save")
> save(createobj)
>
> unbound method save() must be called with Foo instance as first
> argument (got ModelBase instance instead)
>
> i've probably gone about the whole problem all wrong, so feel feel to
> correct this approach if it is way off base
>
> >
>

Does this work?

from myproject.test.models import Foo
f = Foo(name="bar")
f.save()


Colin

--~--~---------~--~----~------------~-------~--~----~
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