Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

bocribbz
Copy link

Add support to update tags by appending, instead of replacing existing ones.

class TagManager(models.Manager):
def update_tags(self, obj, tag_names):
def update_tags(self, obj, tag_names, replace_existing=True):
Copy link
Author

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
Copy link
Author

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]
Copy link
Author

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):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test is here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant