-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update tags with optional replace existing tags flag. #3
base: master
Are you sure you want to change the base?
Conversation
class TagManager(models.Manager): | ||
def update_tags(self, obj, tag_names): | ||
def update_tags(self, obj, tag_names, replace_existing=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actual change
updated_tag_names = [t.lower() for t in updated_tag_names] | ||
|
||
# Remove tags which no longer apply |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actual change
object_id=obj.pk, | ||
tag__in=tags_for_removal, | ||
).delete() | ||
|
||
# Add new tags | ||
current_tag_names = [tag.name for tag in current_tags] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bellow are pep8 fixes. check the tests ;)
@@ -234,6 +295,26 @@ def test_update_tags(self): | |||
self.failUnless(get_tag('baz') in tags) | |||
self.failUnless(get_tag('foo') in tags) | |||
|
|||
def test_update_tags_without_replace(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new test is here!
Add support to update tags by appending, instead of replacing existing ones.