Login

Slice filter

Author:
sneeu
Posted:
March 6, 2007
Language:
Python
Version:
Pre .96
Tags:
filter string slice simple
Score:
-1 (after 7 ratings)

Handy for things such as: {{ some_string|slice:","|join:";" }}

1
2
3
@register.filter
def slice(s, delimiter=' '):
    return s.slice(delimiter)

More like this

  1. Call a manager method on any model with a filter by coleifer 4 years, 11 months ago
  2. truncatechars filter by semente 5 years, 7 months ago
  3. Make tags easier with properties by ubernostrum 8 years, 1 month ago
  4. Save Admin ChangeList Filter by msaron 3 years, 3 months ago
  5. Changelist filter by ForeignKey by overclocked 4 years, 5 months ago

Comments

jcroft (on March 6, 2007):

The name "slice" conflicts with the built-in "slice" filter. I'd definitely recommend anyone who use this change the name, or you could be headed for troubled.

#

jacobian (on March 6, 2007):

Yeah, I'm not sure this works at all... strings don't have a "slice" method, so likely this doesn't do anything except throw an error.

#

whiskybar (on March 7, 2007):

Did you mean split?

#

sneeu (on March 14, 2007):

Ah yes, sorry - it should be called split.

#

Please login first before commenting.