remove_notes.py 851 Bytes
#-*- coding:utf-8 -*-

"""Script for removing notes with specified text string."""

from django.core.management.base import BaseCommand

from dictionary.models import *

class Command(BaseCommand):
    'Slowal command for removing messages with specified text string.'
    help = 'Remove messages with specified text string.'

    def handle(self, **options):
        remove_notes()  

def remove_notes():
    'Remove messages with specified text string.'
    print 'Be patient, it can take a while.'
    notes_to_remove = [u'.', u'bez komentarza.']
    for message in Message.objects.all():
        text = message.message_text.lower().strip()
        if text in notes_to_remove:
            print '!!!!!!!!!!delete!!!!!!!!!!!!'
            print message.sender
            print message.message_text
            message.delete()