1. Alessandro Pagnin
  2. django-tagging

Commits

alenad  committed 0901143 Draft

- Now add_tag and update_tags managers return informations about what has been done (tagged item creation or not, new tagged items, removed tags)

  • Participants
  • Parent commits 9e47404
  • Branches default

Comments (0)

Files changed (1)

File tagging/models.py

View file
  • Ignore whitespace
                                                object_id=obj.pk,
                                                tag__in=tags_for_removal).delete()
         # Add new tags
+        new_tagged_items = []
         current_tag_names = [tag.name for tag in current_tags]
         for tag_name in updated_tag_names:
             if tag_name not in current_tag_names:
                 tag, created = self.get_or_create(name=tag_name)
-                TaggedItem._default_manager.create(tag=tag, object=obj)
+                tagged_item = TaggedItem._default_manager.create(tag=tag, object=obj)
+                new_tagged_items.append(tagged_item)
+
+        return tags_for_removal, new_tagged_items
 
     def add_tag(self, obj, tag_name):
         """
         tag_name = tag_names[0]
         if settings.FORCE_LOWERCASE_TAGS:
             tag_name = tag_name.lower()
-        tag, created = self.get_or_create(name=tag_name)
+        tag, _ = self.get_or_create(name=tag_name)
         ctype = ContentType.objects.get_for_model(obj)
-        TaggedItem._default_manager.get_or_create(
+        tagged_item, created = TaggedItem._default_manager.get_or_create(
             tag=tag, content_type=ctype, object_id=obj.pk)
+        
+        return tagged_item, created
 
     def get_for_object(self, obj):
         """