Wednesday, February 2, 2011

Re: variable column name

On 2 fév, 20:48, Tony <tonyl7...@gmail.com> wrote:
> for example,
> I have t = 'bar' and foo = modelName.objects.get(id = 4)
> I want to do something like:
> foo.t = "new value" or foo[t] = "new value" (but those dont work).

setattr(foo, t, "new value")


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

No comments:

Post a Comment