Skip to content

Commit

Permalink
add auto_tag_objects util function
Browse files Browse the repository at this point in the history
  • Loading branch information
jlecker committed May 10, 2011
1 parent a9c4692 commit 8d4b016
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mediaman/utils.py
Expand Up @@ -58,3 +58,9 @@ def tags_from_string(phrase):
word_list = re.findall(r'[A-Za-z0-9]+', phrase.lower())
word_list = [word for word in word_list if word not in ignore_list]
return Tag.objects.filter(name__in=word_list).values_list('name', flat=True)


def auto_tag_objects(obj_list, from_field, tag_field='tags'):
for obj in obj_list:
tag_list = tags_from_string(getattr(obj, from_field, ''))
getattr(obj, tag_field).add(*tag_list)

0 comments on commit 8d4b016

Please sign in to comment.