From 812a2242fe5af9605129e171c1a1f31918742f3c Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Fri, 19 Feb 2021 15:44:08 -0500 Subject: [PATCH] feat: added more fields to admin --- innovate/admin.py | 20 ++++++++++++++++---- innovate/models.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/innovate/admin.py b/innovate/admin.py index 8c3caa4..bbef642 100644 --- a/innovate/admin.py +++ b/innovate/admin.py @@ -14,18 +14,30 @@ admin_site = LaunchXAdminSite(name='launchx-admin') admin_site.register(User) admin_site.register(Group) -admin_site.register(Judge) -admin_site.register(Score) +class JudgeAdmin(admin.ModelAdmin): + list_display = ("name", "scores_left", "color") -admin_site.register(Competitor) +admin_site.register(Judge, JudgeAdmin) + +class ScoreAdmin(admin.ModelAdmin): + list_display = ("__str__", "get_total_score") +admin_site.register(Score, ScoreAdmin) + +class CompetitorAdmin(admin.ModelAdmin): + list_display = ('__str__', 'email', 'team') + +admin_site.register(Competitor, CompetitorAdmin) class CompetitorInline(admin.TabularInline): model = Competitor + class TeamAdmin(admin.ModelAdmin): inlines = [ CompetitorInline, ] - + + list_display = ('number', 'name', 'feedback_recieved', 'score_average') + ordering = ('number',) admin_site.register(Team, TeamAdmin) \ No newline at end of file diff --git a/innovate/models.py b/innovate/models.py index f39e45d..7291466 100644 --- a/innovate/models.py +++ b/innovate/models.py @@ -23,6 +23,20 @@ class Team(models.Model): def __str__(self): return f'Team {self.number}: {self.name}' + @property + def feedback_recieved(self): + return Score.objects.filter(team=self).count() + + @property + def score_average(self): + scores = Score.objects.filter(team=self) + if scores.count() == 0: + return 0 + average = 0 + for score in scores: + average += score.get_total_score + return round(average / scores.count(), 2) + # def clean(self): # # Don't allow teams to have the same name. # if Team.objects.filter(name=self.name).count() > 0: @@ -62,6 +76,20 @@ class Judge(models.Model): def __str__(self): return f'Judge {self.user.last_name}' + + @property + def name(self): + return self.user.get_full_name() + + @property + def scores_left(self): + all_teams = len([team.number for team in Team.objects.all() if ((team.number % 2 == 0 and self.isEven) or (team.number % 2 != 0 and not self.isEven))]) + completed_teams = Score.objects.filter(judge=self).count() + return f'{completed_teams}/{all_teams}' + + @property + def color(self): + return 'Blue' if self.isEven else 'Red' class Score(models.Model): judge = models.ForeignKey(Judge, on_delete=models.CASCADE) @@ -89,6 +117,7 @@ class Score(models.Model): def __str__(self): return f'Team {self.team.number}\'s Feedback from {self.judge.user.get_full_name()}' + @property def get_total_score(self): fields = [self.innovation, self.need, self.finances, self.creativity, self.qna, self.speaking, self.persuasiveness, self.professionalism] return sum(fields) \ No newline at end of file