On Apr 29, 12:09 pm, Dennis Schmidt <metzelti...@googlemail.com>
wrote:
> Hi Mike,
>
> thanks a lot but that was unfortunately not what I ment. Your
> assignmements are static in
>
> In [2]: n = TestFun(name="mike", description="Testing is always
> fun.")
>
> but I need them to be dynamic. So in the above case NAME wouldn't be
> hardcoded but come from a dictionary. {'name': 'mike'} like this.
> I just found at least some way:
>
> newCustomer = Customer()
>     for key, value in params.iteritems():
>         newCustomer.__setattr__(key, value)
>
> where PARAMS is my dictionary. It works but I don't think this is
> really elegant...

You can just do this:
newCustomer = Customer.objects.create(**params)
--
DR
--~--~---------~--~----~------------~-------~--~----~
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