diff --git a/jdav_web/material/admin.py b/jdav_web/material/admin.py index 986ab8d..f285118 100644 --- a/jdav_web/material/admin.py +++ b/jdav_web/material/admin.py @@ -36,7 +36,7 @@ class NotTooOldFilter(SimpleListFilter): class MaterialAdmin(admin.ModelAdmin): """Edit view of a MaterialPart""" - list_display = ('name', 'buy_date', 'lifetime', 'not_too_old', 'photo') + list_display = ('name', 'quantity_real', 'buy_date', 'lifetime', 'not_too_old', 'photo') inlines = [OwnershipInline] list_filter = (NotTooOldFilter,) diff --git a/jdav_web/material/materials.json b/jdav_web/material/materials.json index 32c2bac..da53968 100644 --- a/jdav_web/material/materials.json +++ b/jdav_web/material/materials.json @@ -5,7 +5,8 @@ "fields": { "name": "Seil 40m grĂ¼n", "buy_date": "2016-01-01", - "lifetime": "3" + "lifetime": "3", + "quantity": "3" } }, { @@ -14,7 +15,8 @@ "fields": { "name": "Seil 40m blau", "buy_date": "2012-01-01", - "lifetime": "3" + "lifetime": "3", + "quantity": "10" } }, { @@ -23,7 +25,8 @@ "fields": { "name": "Seil 60m gelb", "buy_date": "2013-01-01", - "lifetime": "3" + "lifetime": "3", + "quantity": "5" } }, { @@ -32,7 +35,8 @@ "fields": { "name": "Seil 60m blau", "buy_date": "2016-01-01", - "lifetime": "3" + "lifetime": "3", + "quantity": "2" } } ] \ No newline at end of file diff --git a/jdav_web/material/models.py b/jdav_web/material/models.py index 131eec9..cc6226b 100644 --- a/jdav_web/material/models.py +++ b/jdav_web/material/models.py @@ -15,15 +15,23 @@ class MaterialPart(models.Model): members of the association (Ownership) """ name = models.CharField(_('name'), max_length=30) + quantity = models.IntegerField(_('quantity'), default=0) buy_date = models.DateField(_('purchase date'), editable=True) - lifetime = models.DecimalField(_('lifetime (years)'), decimal_places=0, - max_digits=3) + lifetime = models.DecimalField(_('lifetime (years)'), decimal_places=0, max_digits=3) photo = models.ImageField(_('photo'), upload_to='images', blank=True) def __str__(self): """String representation""" return self.name + def quantity_real(self): + real = sum([o.count for o in Ownership.objects.filter(material__id = self.pk)]) + return str(real) + '/' + str(self.quantity) + + quantity_real.admin_order_field = 'quantity' + quantity_real.short_description = _('Quantity') + + def not_too_old(self): """Returns wether the part should be replaced cause of age""" buy_time = timezone.make_aware(datetime.combine(self.buy_date,