2π
β
In split_tags
function you are only iterating alltags
without saving result from urlify
. You can do it in one line with list comprehension:
def split_tags(self):
return [urlify(tag) for tag in self.tags.split(', ')]
Your version need some changes:
def split_tags(self):
alltags = self.tags.split(', ')
result = []
for tag in alltags:
result.append(urlify(tag))
return result
Note that there is similar to your urlify
function in django utils β slugify
:
slugify()
Converts to lowercase, removes non-word characters
(alphanumerics and underscores) and converts spaces to hyphens. Also
strips leading and trailing whitespace.
π€ndpu
Source:stackexchange.com