# Path: shownotes/models.py
# class Topic(models.Model):
#     name = models.CharField(max_length=100)
# 
#     def note_count(self):
#         return Note.objects.filter(topic__id=self.id).count()
# 
#     def __unicode__(self):
#         return self.name
# 
#     @classmethod
#     def get_by_id(cls, *ids):
#         if len(ids) == 0:
#             return []
#         qs = [Q(id=x) for x in ids]
#         query = reduce(lambda x, y: x | y, qs)
#         return Topic.objects.filter(query)
# 
#     @classmethod
#     def exists(cls, name):
#         return Topic.objects.filter(name=name).count() > 0


from shownotes.models import Topic
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = '''Merges topics that are meant to be the same
              prior to index building'''
    BAD_TOPICS = []

    def delete_empty_topics(self):
        unused_topics = [t for t in Topic.objects.all()
                         if t.note_count() == 0]
        for topic in unused_topics:
            topic.delete()

    def delete_bad_topics(self):

# Path: shownotes/models.py
# class Topic(models.Model):
#     name = models.CharField(max_length=100)
# 
#     def note_count(self):
#         return Note.objects.filter(topic__id=self.id).count()
# 
#     def __unicode__(self):
#         return self.name
# 
#     @classmethod
#     def get_by_id(cls, *ids):
#         if len(ids) == 0:
#             return []
#         qs = [Q(id=x) for x in ids]
#         query = reduce(lambda x, y: x | y, qs)
#         return Topic.objects.filter(query)
# 
#     @classmethod
#     def exists(cls, name):
#         return Topic.objects.filter(name=name).count() > 0


# Path: shownotes/management/commands/clean_topics.py
from shownotes.models import Topic
from django.core.management.base import BaseCommand



class Command(BaseCommand):
    help = '''Merges topics that are meant to be the same
              prior to index building'''
    BAD_TOPICS = []

    def delete_empty_topics(self):
        unused_topics = [t for t in Topic.objects.all()
                         if t.note_count() == 0]
        for topic in unused_topics:
            topic.delete()

    def delete_bad_topics(self):

        for topic in Topic.objects.filter(name__in=Command.BAD_TOPICS):