mirror of
https://github.com/Rushilwiz/launchx.git
synced 2025-04-05 04:30:19 -04:00
feat: added more fields to admin
This commit is contained in:
parent
e6e3be0ec2
commit
812a2242fe
|
@ -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)
|
|
@ -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:
|
||||
|
@ -63,6 +77,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)
|
||||
team = models.ForeignKey(Team, 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)
|
Loading…
Reference in New Issue
Block a user