Add count and cost of consumables to buy
This commit is contained in:
parent
a8d0c18b20
commit
c7ad114c5c
2 changed files with 28 additions and 1 deletions
|
@ -34,7 +34,15 @@ class TeacherResource(resources.ModelResource):
|
||||||
|
|
||||||
@admin.register(Level)
|
@admin.register(Level)
|
||||||
class LevelAdmin(admin.ModelAdmin):
|
class LevelAdmin(admin.ModelAdmin):
|
||||||
list_display = ['name', 'order', 'book_count', 'consumable_count', 'consumable_price']
|
list_display = [
|
||||||
|
'name',
|
||||||
|
'order',
|
||||||
|
'book_count',
|
||||||
|
'consumable_count',
|
||||||
|
'consumable_price',
|
||||||
|
'non_acquired_consumable_count',
|
||||||
|
'non_acquired_consumable_price'
|
||||||
|
]
|
||||||
list_editable = ['order']
|
list_editable = ['order']
|
||||||
list_display_links = ['name']
|
list_display_links = ['name']
|
||||||
|
|
||||||
|
@ -50,6 +58,14 @@ class LevelAdmin(admin.ModelAdmin):
|
||||||
return f'{obj.consumable_price:.2f}€'
|
return f'{obj.consumable_price:.2f}€'
|
||||||
consumable_price.short_description = 'Coût des consommables'
|
consumable_price.short_description = 'Coût des consommables'
|
||||||
|
|
||||||
|
def non_acquired_consumable_count(self, obj: Level):
|
||||||
|
return obj.non_acquired_consumable_count
|
||||||
|
non_acquired_consumable_count.short_description = 'Nombre de consommable(s) à acheter cette année'
|
||||||
|
|
||||||
|
def non_acquired_consumable_price(self, obj: Level):
|
||||||
|
return f'{obj.non_acquired_consumable_price:.2f}€'
|
||||||
|
non_acquired_consumable_price.short_description = 'Coût des consommables à acheter cette année'
|
||||||
|
|
||||||
|
|
||||||
class BookResource(resources.ModelResource):
|
class BookResource(resources.ModelResource):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -120,6 +120,10 @@ class Level(BaseModel):
|
||||||
def consumable_count(self):
|
def consumable_count(self):
|
||||||
return self.book_set.filter(consumable=True).count()
|
return self.book_set.filter(consumable=True).count()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def non_acquired_consumable_count(self):
|
||||||
|
return self.book_set.filter(consumable=True, previously_acquired=False).count()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def consumable_price(self):
|
def consumable_price(self):
|
||||||
price = self.book_set.filter(consumable=True).aggregate(Sum('price')).get('price__sum', 0)
|
price = self.book_set.filter(consumable=True).aggregate(Sum('price')).get('price__sum', 0)
|
||||||
|
@ -127,6 +131,13 @@ class Level(BaseModel):
|
||||||
return 0
|
return 0
|
||||||
return price
|
return price
|
||||||
|
|
||||||
|
@property
|
||||||
|
def non_acquired_consumable_price(self):
|
||||||
|
price = self.book_set.filter(consumable=True, previously_acquired=False).aggregate(Sum('price')).get('price__sum', 0)
|
||||||
|
if price is None:
|
||||||
|
return 0
|
||||||
|
return price
|
||||||
|
|
||||||
|
|
||||||
class Editor(BaseModel):
|
class Editor(BaseModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Reference in a new issue