new admin !
This commit is contained in:
parent
6e993c0e27
commit
8dee36f928
2 changed files with 75 additions and 10 deletions
|
@ -63,8 +63,8 @@ class EquipmentAttributeValueInline(admin.TabularInline):
|
||||||
|
|
||||||
|
|
||||||
class CategoryAdmin(admin.ModelAdmin):
|
class CategoryAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ['full_name']
|
readonly_fields = ['full_name_p']
|
||||||
list_display = ['name', 'parent', "full_name"]
|
list_display = ['name', 'parent', "full_name_p"]
|
||||||
ordering = ['name', 'parent']
|
ordering = ['name', 'parent']
|
||||||
search_fields = ['name',]
|
search_fields = ['name',]
|
||||||
|
|
||||||
|
@ -76,8 +76,39 @@ class EquipmentAttributeAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
|
||||||
class EquipmentAdmin(admin.ModelAdmin):
|
class EquipmentAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ['full_category', 'added_at', 'modified_at',]
|
readonly_fields = ['full_category_p',
|
||||||
|
'added_at',
|
||||||
|
'modified_at',
|
||||||
|
'stock_aviable_p',
|
||||||
|
'ids_aviable_p',
|
||||||
|
'stock_lost_p',
|
||||||
|
'ids_lost_p',
|
||||||
|
]
|
||||||
list_display = ['name', 'stock', 'owner', 'category', 'modified_at']
|
list_display = ['name', 'stock', 'owner', 'category', 'modified_at']
|
||||||
|
fieldsets = (
|
||||||
|
('Général', {
|
||||||
|
'fields': ('name', 'owner', 'stock', )
|
||||||
|
}),
|
||||||
|
('Info stock',
|
||||||
|
{
|
||||||
|
'fields': (
|
||||||
|
'stock_aviable_p',
|
||||||
|
'ids_aviable_p',
|
||||||
|
'stock_lost_p',
|
||||||
|
'ids_lost_p',
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
('Catégorie', {
|
||||||
|
'fields': ('category', 'full_category_p'),
|
||||||
|
}),
|
||||||
|
('Description', {
|
||||||
|
'fields': ('description', 'added_at', 'modified_at',),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ordering = ['name', 'owner', 'category']
|
ordering = ['name', 'owner', 'category']
|
||||||
inlines = [EquipmentAttributeValueInline,
|
inlines = [EquipmentAttributeValueInline,
|
||||||
EquipmentDefaultExtraInline,
|
EquipmentDefaultExtraInline,
|
||||||
|
|
|
@ -23,7 +23,7 @@ class EquipmentCategory(models.Model):
|
||||||
help_text=_("merci de ne pas faire de référence cyclique"),
|
help_text=_("merci de ne pas faire de référence cyclique"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def full_name_property(self):
|
def full_name(self):
|
||||||
if self.parent is None:
|
if self.parent is None:
|
||||||
return "-"
|
return "-"
|
||||||
current = self
|
current = self
|
||||||
|
@ -37,8 +37,8 @@ class EquipmentCategory(models.Model):
|
||||||
current = current.parent
|
current = current.parent
|
||||||
return res
|
return res
|
||||||
|
|
||||||
full_name_property.short_description = _("Chemin complet")
|
full_name.short_description = _("Chemin complet")
|
||||||
full_name = property(full_name_property)
|
full_name_p = property(full_name)
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -97,11 +97,45 @@ class Equipment(EventSpecificMixin, models.Model):
|
||||||
auto_now=True,
|
auto_now=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def full_category_property(self):
|
def ids_aviable(self):
|
||||||
return self.category.full_name_property()
|
res = map(lambda x: x+1, range(self.stock))
|
||||||
|
for lost in self.losts.all():
|
||||||
|
res = [ x
|
||||||
|
for x in res
|
||||||
|
if x not in lost.ids ]
|
||||||
|
# TODO cassé
|
||||||
|
# TODO utilisés
|
||||||
|
return res
|
||||||
|
|
||||||
full_category_property.short_description = _("Chemin complet")
|
def ids_lost(self):
|
||||||
full_category= property(full_category_property)
|
res = []
|
||||||
|
for lost in self.losts.all():
|
||||||
|
res = res + [ x
|
||||||
|
for x in lost.ids
|
||||||
|
if x not in res]
|
||||||
|
return res
|
||||||
|
|
||||||
|
def stock_aviable(self):
|
||||||
|
return len(self.ids_available())
|
||||||
|
|
||||||
|
def stock_lost(self):
|
||||||
|
return len(self.ids_lost())
|
||||||
|
|
||||||
|
def full_category(self):
|
||||||
|
return self.category.full_name()
|
||||||
|
|
||||||
|
full_category.short_description = _("Chemin complet")
|
||||||
|
ids_aviable.short_description = _("disponibles")
|
||||||
|
ids_lost.short_description = _("perdus")
|
||||||
|
stock_aviable.short_description= _("quantité disponible")
|
||||||
|
stock_lost.short_description = _("quantité perdue")
|
||||||
|
|
||||||
|
full_category_p= property(full_category)
|
||||||
|
ids_aviable_p= property(ids_aviable)
|
||||||
|
ids_lost_p= property(ids_lost)
|
||||||
|
stock_aviable_p= property(stock_aviable)
|
||||||
|
stock_lost_p = property(stock_lost)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Reference in a new issue