equipment attributes
This commit is contained in:
parent
c8f4ab1a80
commit
70d1d403f6
3 changed files with 92 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
from django.contrib import admin
|
||||
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 shared.admin import admin_site
|
||||
|
@ -57,19 +57,31 @@ class EquipmentLostExtraInline(admin.TabularInline):
|
|||
classes = ['collapse']
|
||||
|
||||
|
||||
class EquipmentAttributeValueInline(admin.TabularInline):
|
||||
model = EquipmentAttributeValue
|
||||
extra = 0
|
||||
|
||||
|
||||
class CategoryAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'parent']
|
||||
ordering = ['name', 'parent']
|
||||
|
||||
|
||||
class EquipmentAttributeAdmin(admin.ModelAdmin):
|
||||
list_display = ['name']
|
||||
ordering = ['name']
|
||||
|
||||
|
||||
class EquipmentAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'stock', 'owner', 'category']
|
||||
ordering = ['name', 'owner', 'category']
|
||||
inlines = [EquipmentDefaultExtraInline,
|
||||
inlines = [EquipmentAttributeValueInline,
|
||||
EquipmentDefaultExtraInline,
|
||||
EquipmentLostExtraInline,
|
||||
EquipmentRevisionExtraInline]
|
||||
|
||||
|
||||
admin_site.register(Equipment, EquipmentAdmin)
|
||||
admin_site.register(EquipmentCategory, CategoryAdmin)
|
||||
admin_site.register(EquipmentAttribute, EquipmentAttributeAdmin)
|
||||
admin.site.register(Equipment, EquipmentAdmin)
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -60,6 +60,44 @@ class Equipment(EventSpecificMixin, models.Model):
|
|||
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):
|
||||
equipment = models.ForeignKey(Equipment)
|
||||
activity = models.ForeignKey(Activity)
|
||||
|
|
Loading…
Reference in a new issue