Added ability to see current house points
This commit is contained in:
parent
6cd4bb0075
commit
d9d0057fa4
4 changed files with 15 additions and 14 deletions
|
|
@ -5,13 +5,13 @@ from ..models import House
|
|||
|
||||
@admin.register(House)
|
||||
class HouseAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'points')
|
||||
list_display = ('name', 'points', 'current_points', 'total_points')
|
||||
actions = ['finalize_points']
|
||||
|
||||
# @admin.display(description='Current Housewars Points')
|
||||
# def current_points(self, obj):
|
||||
# return obj.current_points
|
||||
@admin.display(description='Current Housewars Points')
|
||||
def current_points(self, obj):
|
||||
return obj.current_points
|
||||
|
||||
# @admin.display(description='Total Points')
|
||||
# def total_points(self, obj):
|
||||
# return obj.total_points
|
||||
@admin.display(description='Total Points')
|
||||
def total_points(self, obj):
|
||||
return obj.total_points
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ class House(models.Model):
|
|||
name = models.CharField(max_length=100)
|
||||
points = models.IntegerField(default=0)
|
||||
|
||||
# @property
|
||||
# def current_points(self):
|
||||
# return self.pointsentry_set.aggregate(points__sum=Coalesce(Sum('points'), 0)).get('points__sum')
|
||||
@property
|
||||
def current_points(self):
|
||||
return self.pointsentry_set.aggregate(sum=Coalesce(Sum('award__points'), 0)).get('sum')
|
||||
|
||||
# @property
|
||||
# def total_points(self):
|
||||
# return self.current_points + self.points
|
||||
@property
|
||||
def total_points(self):
|
||||
return self.current_points + self.points
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from . import Award
|
|||
class PointsEntry(Model):
|
||||
class Meta:
|
||||
verbose_name_plural = "Point Entries"
|
||||
unique_together = ('activity', 'award')
|
||||
|
||||
activity = ForeignKey(
|
||||
'Activity', related_name='Activity', on_delete=CASCADE)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from . import House, Activity
|
|||
|
||||
class Teacher(models.Model):
|
||||
class Meta:
|
||||
unique_together = [['house', 'grade']]
|
||||
unique_together = ('house', 'grade')
|
||||
|
||||
GradeChoices = (
|
||||
(9, '9th/Freshman'),
|
||||
|
|
|
|||
Reference in a new issue