#-*- coding:utf-8 -*- import operator from django.core.management.base import BaseCommand from django.db.models import Q from django.utils.encoding import smart_str from dictionary.models import Lemma class Command(BaseCommand): args = 'none' help = """Find lemmas which were checked by supelexicographer being also their owner.""" def handle(self, **options): same_superlex() def same_superlex(): q_status_list = [] q_status_list.append(Q(status__status=u'sprawdzone')) lemmas = Lemma.objects.filter(old=False).filter(reduce(operator.or_, q_status_list)) for lemma in lemmas.all(): check_stat_changes = lemma.status_history.filter(status__status=u'sprawdzone').all() if (len(check_stat_changes) > 0 and (check_stat_changes[len(check_stat_changes)-1].act_owner == check_stat_changes[len(check_stat_changes)-1].changer)): print smart_str(lemma) else: continue