Commits

Anonymous committed 1db9f01

Add auto-tag Admin action

Comments (0)

Files changed (1)

gnocchi/blog/admin.py

             obj.posted_by = request.user
         obj.save()
 
+    def auto_tag(self, request, queryset):
+        for post in queryset:
+            tags = post.tags.all()
+            tags.update([
+                tag
+                for tag in TaggedItem.tags_for(models.Post)
+                if re.search(r'\b%s\b' % tag.name, post.content, re.I|re.M)
+            ])
+            post.tags.set(*tags)
+
+    actions = [
+        auto_tag,
+    ]
+
 register(models.Post, PostAdmin)
 
 class CommentAdmin(admin.ModelAdmin):