from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.exceptions import ObjectDoesNotExist
from django.utils import translation, timezone
from django.contrib.auth.models import User
from events.models import Event,Abstract
from clubs.models import Team
from django.db.models import Count



class Command(BaseCommand):
    help = "Assign abstract to evaluators"

    def handle(self, *args, **options):
        event= Event.objects.get(code_name='hpc2-r')
        abstracrs_count = Abstract.objects.filter(event=event).count()
        evaluatin_team_members_count = Team.objects.get(code_name="hpc2-r-e").members.count()
        assigened_abstrsts_count = int(abstracrs_count/evaluatin_team_members_count)
        avalabile_members= Team.objects.get(code_name="hpc2-r-e").members.annotate(num_b=Count('abstract')).filter(num_b__lt=assigened_abstrsts_count)
        unassigned_abstracts = Abstract.objects.annotate(num_b=Count('evaluators')).filter(event=event, is_deleted=False,num_b__lt=2)
        for abstract in unassigned_abstracts:
            for member in avalabile_members:
                if member not in abstract.evaluators.all():
                    abstract.evaluators.add(member)
                    abstract.save()
@@ -331,17 +331,16 @@
 Count%0A%0A%0A
-%0A
 class Co
@@ -406,101 +406,520 @@
 rs%22%0A
-%0A    def handle(self, *args, **options):%0A        event= Event.objects.get(code_name='hpc2-r')
+    def add_arguments(self, parser):%0A        parser.add_argument('--event-code-name', dest='event_code_name',%0A                            default=None, type=str)%0A%0A    def handle(self, *args, **options):%0A        if not options%5B'event_code_name'%5D:%0A            print %22No event code name was provided.%22%0A            return%0A%0A        event= Event.objects.get(code_name=options%5B'event_code_name'%5D)%0A%0A        if not event.abstract_revision_team:%0A            print %22Event has no abstract revision team.%22%0A            return%0A
 %0A   
@@ -1048,34 +1048,52 @@
 t(code_name=
-%22hpc2-r-e%22
+event.abstract_revision_team
 ).members.co
@@ -1098,24 +1098,25 @@
 count()%0A
+%0A
         
 assigene
@@ -1107,34 +1107,22 @@
         
-assigened_abstrsts
+target
 _count =
@@ -1230,18 +1230,36 @@
 ame=
-%22hpc2-r-e%22
+event.abstract_revision_team
 ).me
@@ -1319,34 +1319,22 @@
 _lt=
-assigened_abstrsts
+target
 _count)%0A
     
@@ -1321,32 +1321,33 @@
 t=target_count)%0A
+%0A
         unassign
@@ -1702,8 +1702,9 @@
 t.save()
+%0A

Improve management command