Commit 5c35d4f9 by Alex Gaynor

Clean up the API.

parent 2311ed28
...@@ -10,7 +10,7 @@ class TaggableForm(forms.ModelForm): ...@@ -10,7 +10,7 @@ class TaggableForm(forms.ModelForm):
obj = super(TaggableForm, self).save(commit=False) obj = super(TaggableForm, self).save(commit=False)
def save_tags(): def save_tags():
# TODO: Remove the assumption that the manager is named 'tags' # TODO: Remove the assumption that the manager is named 'tags'
obj.tags.set(parse_tags(self.cleaned_data['tags'])) obj.tags.set(*parse_tags(self.cleaned_data['tags']))
if commit: if commit:
obj.save() obj.save()
save_tags() save_tags()
......
...@@ -26,23 +26,19 @@ class _TaggableManager(models.Manager): ...@@ -26,23 +26,19 @@ class _TaggableManager(models.Manager):
return Tag.objects.filter(items__content_type=ct).distinct() return Tag.objects.filter(items__content_type=ct).distinct()
@require_instance_manager @require_instance_manager
def add(self, tags): def add(self, *tags):
if isinstance(tags, basestring):
tags = [tags]
for tag in tags: for tag in tags:
tag, _ = Tag.objects.get_or_create(name=tag) tag, _ = Tag.objects.get_or_create(name=tag)
TaggedItem.objects.create(object_id=self.object_id, TaggedItem.objects.create(object_id=self.object_id,
content_type=ContentType.objects.get_for_model(self.model), tag=tag) content_type=ContentType.objects.get_for_model(self.model), tag=tag)
@require_instance_manager @require_instance_manager
def set(self, tags): def set(self, *tags):
self.clear() self.clear()
self.add(tags) self.add(*tags)
@require_instance_manager @require_instance_manager
def remove(self, tags): def remove(self, *tags):
if isinstance(tags, basestring):
tags = [tags]
TaggedItem.objects.filter(object_id=self.object_id, TaggedItem.objects.filter(object_id=self.object_id,
content_type=ContentType.objects.get_for_model(self.model)).filter( content_type=ContentType.objects.get_for_model(self.model)).filter(
tag__name__in=tags).delete() tag__name__in=tags).delete()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment