feat: added more fields to admin

This commit is contained in:
Rushil Umaretiya 2021-02-19 15:44:08 -05:00
parent e6e3be0ec2
commit 812a2242fe
2 changed files with 45 additions and 4 deletions

View File

@ -14,18 +14,30 @@ admin_site = LaunchXAdminSite(name='launchx-admin')
admin_site.register(User) admin_site.register(User)
admin_site.register(Group) admin_site.register(Group)
admin_site.register(Judge) class JudgeAdmin(admin.ModelAdmin):
admin_site.register(Score) 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): class CompetitorInline(admin.TabularInline):
model = Competitor model = Competitor
class TeamAdmin(admin.ModelAdmin): class TeamAdmin(admin.ModelAdmin):
inlines = [ inlines = [
CompetitorInline, CompetitorInline,
] ]
list_display = ('number', 'name', 'feedback_recieved', 'score_average')
ordering = ('number',)
admin_site.register(Team, TeamAdmin) admin_site.register(Team, TeamAdmin)

View File

@ -23,6 +23,20 @@ class Team(models.Model):
def __str__(self): def __str__(self):
return f'Team {self.number}: {self.name}' 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): # def clean(self):
# # Don't allow teams to have the same name. # # Don't allow teams to have the same name.
# if Team.objects.filter(name=self.name).count() > 0: # if Team.objects.filter(name=self.name).count() > 0:
@ -63,6 +77,20 @@ class Judge(models.Model):
def __str__(self): def __str__(self):
return f'Judge {self.user.last_name}' 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): class Score(models.Model):
judge = models.ForeignKey(Judge, on_delete=models.CASCADE) judge = models.ForeignKey(Judge, on_delete=models.CASCADE)
team = models.ForeignKey(Team, on_delete=models.CASCADE) team = models.ForeignKey(Team, on_delete=models.CASCADE)
@ -89,6 +117,7 @@ class Score(models.Model):
def __str__(self): def __str__(self):
return f'Team {self.team.number}\'s Feedback from {self.judge.user.get_full_name()}' return f'Team {self.team.number}\'s Feedback from {self.judge.user.get_full_name()}'
@property
def get_total_score(self): def get_total_score(self):
fields = [self.innovation, self.need, self.finances, self.creativity, self.qna, self.speaking, self.persuasiveness, self.professionalism] fields = [self.innovation, self.need, self.finances, self.creativity, self.qna, self.speaking, self.persuasiveness, self.professionalism]
return sum(fields) return sum(fields)