On Sat, Jul 10, 2010 at 12:01 AM, zweb <traderash...@gmail.com> wrote:
> I want to provide a method as follows,
>
> def update_some_model_field(key, field_name, value):
>  '''user provides the primary key of row, field name in model and the
> value and the method updates the field for that row with the value'''
>
> 1.  model_obj = Some_model.objects.get(pk = key)
> 2.  model_obj."field_name" = value  ## HOW to make this line generic??
> I do not want to do lots of If as shown below.
> 3. model_obj.save()
[...]
>
> Any suggestions?

setattr(model_obj, field_name, value)

~Rolando

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

Reply via email to