It work!

Thank you.

On Jul 4, 9:30 pm, Daniel Roseman <[email protected]> wrote:
> On Jul 4, 12:01 pm, "David.D" <[email protected]> wrote:
>
> > i mean
> > i have a model instance m, and m has a field fd.
> > so i can wrote like this in template
> >    {{ m.fd }}
>
> > but, when i got a string  s = "fd"
>
> > how could i do the same as above?
>
> > thanks for any help...
>
> There's no built-in way. A simple custom filter will do the job.
>
>     @register.filter
>     def field_from_string(instance, fieldname):
>         return getattr(instance, fieldname)
>
> Now you can do:
>
>     {{ m|field_from_string:s }}
>
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to