equipment attributes

This commit is contained in:
Qwann 2018-08-08 16:45:29 +02:00
parent c8f4ab1a80
commit 70d1d403f6
3 changed files with 92 additions and 2 deletions

View file

@ -1,7 +1,7 @@
from django.contrib import admin from django.contrib import admin
from django import forms from django import forms
from .models import Equipment, EquipmentDefault, EquipmentRevision, EquipmentCategory, EquipmentLost from .models import Equipment, EquipmentDefault, EquipmentRevision, EquipmentCategory, EquipmentLost, EquipmentAttributeValue, EquipmentAttribute
from .fields import IdField, IdWidget from .fields import IdField, IdWidget
from shared.admin import admin_site from shared.admin import admin_site
@ -57,19 +57,31 @@ class EquipmentLostExtraInline(admin.TabularInline):
classes = ['collapse'] classes = ['collapse']
class EquipmentAttributeValueInline(admin.TabularInline):
model = EquipmentAttributeValue
extra = 0
class CategoryAdmin(admin.ModelAdmin): class CategoryAdmin(admin.ModelAdmin):
list_display = ['name', 'parent'] list_display = ['name', 'parent']
ordering = ['name', 'parent'] ordering = ['name', 'parent']
class EquipmentAttributeAdmin(admin.ModelAdmin):
list_display = ['name']
ordering = ['name']
class EquipmentAdmin(admin.ModelAdmin): class EquipmentAdmin(admin.ModelAdmin):
list_display = ['name', 'stock', 'owner', 'category'] list_display = ['name', 'stock', 'owner', 'category']
ordering = ['name', 'owner', 'category'] ordering = ['name', 'owner', 'category']
inlines = [EquipmentDefaultExtraInline, inlines = [EquipmentAttributeValueInline,
EquipmentDefaultExtraInline,
EquipmentLostExtraInline, EquipmentLostExtraInline,
EquipmentRevisionExtraInline] EquipmentRevisionExtraInline]
admin_site.register(Equipment, EquipmentAdmin) admin_site.register(Equipment, EquipmentAdmin)
admin_site.register(EquipmentCategory, CategoryAdmin) admin_site.register(EquipmentCategory, CategoryAdmin)
admin_site.register(EquipmentAttribute, EquipmentAttributeAdmin)
admin.site.register(Equipment, EquipmentAdmin) admin.site.register(Equipment, EquipmentAdmin)

View file

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-08-08 14:40
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('equipment', '0006_auto_20180808_1354'),
]
operations = [
migrations.CreateModel(
name='EquipmentAttribute',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, unique=True, verbose_name='nom')),
],
options={
'verbose_name': 'attribut',
'verbose_name_plural': 'attributs',
},
),
migrations.CreateModel(
name='EquipmentAttributeValue',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.CharField(max_length=200, verbose_name='valeur')),
('attribute', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='equipment.EquipmentAttribute')),
('equipment', models.ForeignKey(help_text='Matériel concerné par le defaut', on_delete=django.db.models.deletion.CASCADE, related_name='attributes', to='equipment.Equipment')),
],
options={
'verbose_name': 'attribut de matériel',
'verbose_name_plural': 'attributs de matériel',
},
),
]

View file

@ -60,6 +60,44 @@ class Equipment(EventSpecificMixin, models.Model):
return self.name return self.name
class EquipmentAttribute(models.Model):
name = models.CharField(
_("nom"),
max_length=200,
unique=True,
)
class Meta:
verbose_name = _("attribut")
verbose_name_plural = _("attributs")
def __str__(self):
return self.name
class EquipmentAttributeValue(models.Model):
equipment = models.ForeignKey(
Equipment,
related_name="attributes",
help_text=_("Matériel concerné par le defaut"),
)
attribute = models.ForeignKey(
EquipmentAttribute,
on_delete=models.CASCADE,
)
value = models.CharField(
_("valeur"),
max_length=200,
)
class Meta:
verbose_name = _("attribut de matériel")
verbose_name_plural = _("attributs de matériel")
def __str__(self):
return "{attr}={value}".format(attr=self.attribute.name,
value=self.value)
class EquipmentAttribution(models.Model): class EquipmentAttribution(models.Model):
equipment = models.ForeignKey(Equipment) equipment = models.ForeignKey(Equipment)
activity = models.ForeignKey(Activity) activity = models.ForeignKey(Activity)