Update still takes exactly one argument: self. I'm still not completely clear on what the OP is trying to do so I'll guess that for a given User object (id == 11) you want to adjust a set of attributes not known apriori, but available as key - value pairs from an itterator I'll call 'd.items()':
user = User.objects.get(id=11) for key, value in d.items(): setattr(user, key, value) user.save() On Thu, May 13, 2010 at 2:10 PM, zinckiwi <zinck...@gmail.com> wrote: >> What if field_name and value coming from loop? >> I have around 50 field and values in loop. >> Can I do this? I know this is silly way to do but please guide how can >> I do this? >> >> for key, value in users: >> user."%s" = "%s" % (key, value) >> >> user.save() > > Ah, I see. In that case you will want update(), yes, but you can't > just pass a string to the method. Use the asterisk to convert a list > into arguments, something like (I think): > > list_of_arguments = ["%s=%s" % (key, value) for key, value in > some_dictionary] > user.update(*list_of_arguments) > > Regards > Scott > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.