Merge pull request #16 from Schlabonski/material

add real quantity
v1-0-stable
relnod 9 years ago committed by GitHub
commit a07c0f1bf2

@ -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,)

@ -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"
}
}
]

@ -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,

Loading…
Cancel
Save