On 16/08/09 09:50, GuyBowden wrote: > Hi All, > > Just wondering what the best way to do this sort of thing is: > > {% with last_tweet_sent this_user as sent_at %} > {{ sent_at|naturalday:_("MONTH_DAY_FORMAT")|capfirst}} > {% endwith %} > > I've got a function "last_tweet_sent" in a templatetags module that > takes a user and spits back the last time they sent a tweet. > > I'd like to keep the formatting of the date in the template rather > than in the templatetag module (best practice?) > > But I can't use the with statement to put the result of my function > call in a variable - I guess because of the spacing there for calling > the function with an argument. > > Any suggestions? > > Cheers, > > Guy > Just to clarify, is your last_tweet_sent a template tag or a template filter? In the first instance you won't be able to do what you want, and it's probably overkill. In the second instance you should be able to do:
> {% with this_user|last_tweet_sent as sent_at %} > {{ sent_at|naturalday:_("MONTH_DAY_FORMAT")|capfirst}} > {% endwith %} The template fitler definition would look something like this: > @register.filter(name='last_tweet_sent') > def last_tweet_sent(user): > # work out when it was and call it dt > return dt The alternative is to make it a method on the user object, but that requires a bit more fu in replacing the User model with a custom one. From what I remember, [1] is the place that tells you how to do it. Again, this method is probably overkill ;-). Alex [1] http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/ --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---