On Dec 11, 5:49 am, Scoox <stephan.f.mul...@gmail.com> wrote:
> Okay, I *think* I figured out a way to fix this.
>
> I can add methods such as get_stars to the relevant model.
>
> Then in that method I can do whatever I like with the string (e.g.
> convert it to star symbols).
>
> Would that be the recommended way to do this?
>
> Kind Regards
> Stephan

The "recommended" way would be to use a custom template tag (filter),
which you said you did not wish to do.

If I understand what you want (and I'm not sure that I do), then you
_should_ use a custom filter.  It really is not much different--it's
simply a Python function that returns rendered content.  You can pass
strings or objects as the args.  It would be better in the long run,
because:

1.  There is probably less overhead--you are rendering and doing some
logic inside the same function call, not separate ones.
2.  You can have more specific control over the rendering.
3.  You only have to write one method.  You can put the logic inside
of it that determines what field/object sent it.  If you go the model
method route, you will have to write the same basic logic for each
model.  It's just more code to write/upkeep.

That said, you can use the model method plan, and do the same thing.
I did it before when starting out, but now try to keep model methods
strictly those which modify the model, and rendering/display methods
in filters, since that is where the rendering happens.

Wayne

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