category full name

This commit is contained in:
Qwann 2018-08-09 16:06:24 +02:00
parent ec8e289ff8
commit 14728c8513
3 changed files with 51 additions and 3 deletions

View file

@ -63,7 +63,7 @@ class EquipmentAttributeValueInline(admin.TabularInline):
class CategoryAdmin(admin.ModelAdmin):
list_display = ['name', 'parent']
list_display = ['name', 'parent', "full_name"]
ordering = ['name', 'parent']
@ -73,7 +73,7 @@ class EquipmentAttributeAdmin(admin.ModelAdmin):
class EquipmentAdmin(admin.ModelAdmin):
readonly_fields = ['added_at', 'modified_at']
readonly_fields = ['full_category', 'added_at', 'modified_at',]
list_display = ['name', 'stock', 'owner', 'category', 'modified_at']
ordering = ['name', 'owner', 'category']
inlines = [EquipmentAttributeValueInline,

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-08-09 14:05
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('equipment', '0010_auto_20180809_1211'),
]
operations = [
migrations.AlterField(
model_name='equipment',
name='description',
field=models.TextField(blank=True, verbose_name='description'),
),
]

View file

@ -23,6 +23,24 @@ class EquipmentCategory(models.Model):
help_text=_("merci de ne pas faire de référence cyclique"),
)
def full_name_property(self):
if self.parent is None:
return "-"
current = self
res = ""
for k in range(100):
if current.parent is None:
break
res = "/{current}{old}".format(
current=current.name,
old=res)
current = current.parent
return res
full_name_property.short_description = _("Chemin complet")
full_name = property(full_name_property)
class Meta:
verbose_name = _("catégories")
verbose_name_plural = _("catégories")
@ -51,7 +69,10 @@ class Equipment(EventSpecificMixin, models.Model):
max_length=200,
)
stock = models.PositiveSmallIntegerField(_("quantité totale"))
description = models.TextField(_("description"))
description = models.TextField(
_("description"),
blank=True,
)
activities = models.ManyToManyField(
Activity,
related_name="equipment",
@ -76,6 +97,13 @@ class Equipment(EventSpecificMixin, models.Model):
auto_now=True,
)
def full_category_property(self):
return self.category.full_name_property()
full_category_property.short_description = _("Chemin complet")
full_category= property(full_category_property)
class Meta:
verbose_name = _("matériel")
verbose_name_plural = _("matériels")