Or you could be right. I'm still not clear on the OP's intent. On Thu, May 13, 2010 at 4:21 PM, zinckiwi <zinck...@gmail.com> wrote: > Quite right, I was confusing it with QuerySet's update(), as > demonstrated in the docs: > > # Update all the headlines with pub_date in 2007. > Entry.objects.filter(pub_date__year=2007).update(headline='Everything > is the same') > > Regards > Scott > > > On May 13, 3:14 pm, Bill Freeman <ke1g...@gmail.com> wrote: >> 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 >> > athttp://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 >> athttp://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. > >
-- 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.