diff --git a/equipment/admin.py b/equipment/admin.py index 450203e..7c4de9c 100644 --- a/equipment/admin.py +++ b/equipment/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from django import forms -from .models import Equipment, EquipmentRemark, EquipmentRevision, EquipmentOwner, EquipmentPole, EquipmentCategory +from .models import Equipment, EquipmentDefault, EquipmentRevision, EquipmentOwner, EquipmentPole, EquipmentCategory, EquipmentLost from .fields import IdField, IdWidget from shared.admin import admin_site @@ -39,21 +39,33 @@ class EquipmentRevisionExtraInline(admin.TabularInline): classes = ['collapse'] -class EquipmentRemarkExtraInline(admin.TabularInline): - model = EquipmentRemark +class EquipmentDefaultExtraInline(admin.TabularInline): + model = EquipmentDefault extra = 0 form = IdForm formset = IdFormset classes = ['collapse'] + +class EquipmentLostExtraInline(admin.TabularInline): + model = EquipmentLost + extra = 0 + form = IdForm + formset = IdFormset + classes = ['collapse'] + + class CharFieldModelAdmin(admin.ModelAdmin): list_display = ['name'] ordering = ['name'] + class EquipmentAdmin(admin.ModelAdmin): list_display = ['name', 'stock', 'owner', 'pole', 'category'] ordering = ['name', 'owner', 'pole', 'category'] - inlines = [EquipmentRemarkExtraInline, EquipmentRevisionExtraInline] + inlines = [EquipmentDefaultExtraInline, + EquipmentLostExtraInline, + EquipmentRevisionExtraInline] admin_site.register(Equipment, EquipmentAdmin) diff --git a/equipment/migrations/0002_auto_20180807_1658.py b/equipment/migrations/0002_auto_20180807_1658.py new file mode 100644 index 0000000..fb9e8f2 --- /dev/null +++ b/equipment/migrations/0002_auto_20180807_1658.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.11 on 2018-08-07 16:58 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models +import django.db.models.deletion +import equipment.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('equipment', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='EquipmentDefault', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('remark', models.TextField(verbose_name='remarque sur le défaut')), + ('ids', equipment.fields.IdField()), + ('is_unusable', models.BooleanField(verbose_name='inutilisable')), + ('send_repare', models.BooleanField(verbose_name='à envoyer réparareur')), + ('equipment', models.ForeignKey(help_text='Matériel concerné par le defaut', on_delete=django.db.models.deletion.CASCADE, related_name='remarks', to='equipment.Equipment')), + ], + options={ + 'verbose_name': 'defaut matériel', + 'verbose_name_plural': 'défauts sur le matériel', + }, + ), + migrations.CreateModel( + name='EquipmentLost', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('lost_at', models.DateField(default=datetime.date.today, verbose_name='perdu le')), + ('ids', equipment.fields.IdField()), + ('equipment', models.ForeignKey(help_text='Matériel concerné par la perte', on_delete=django.db.models.deletion.CASCADE, related_name='losts', to='equipment.Equipment')), + ], + ), + migrations.RemoveField( + model_name='equipmentremark', + name='equipment', + ), + migrations.DeleteModel( + name='EquipmentRemark', + ), + ] diff --git a/equipment/models.py b/equipment/models.py index cbc1bbf..7a9e5e3 100644 --- a/equipment/models.py +++ b/equipment/models.py @@ -105,26 +105,39 @@ class EquipmentAttribution(models.Model): super(EquipmentAttribution, self).save(*args, **kwargs) -class EquipmentRemark(models.Model): - remark = models.TextField(_("remarque sur le matériel")) +class EquipmentDefault(models.Model): + remark = models.TextField(_("remarque sur le défaut")) equipment = models.ForeignKey( Equipment, related_name="remarks", - help_text=_("Matériel concerné par la remarque"), + help_text=_("Matériel concerné par le defaut"), ) ids = IdField() - is_broken = models.BooleanField() - is_lost = models.BooleanField() + is_unusable = models.BooleanField(_("inutilisable")) + send_repare = models.BooleanField(_("à envoyer réparareur")) class Meta: - verbose_name = _("remarque sur matériel") - verbose_name_plural = _("remarques sur le matériel") + verbose_name = _("defaut matériel") + verbose_name_plural = _("défauts sur le matériel") def __str__(self): return "%s : %s" % (self.equipment.name, self.remark) +class EquipmentLost(models.Model): + lost_at = models.DateField( + _("perdu le"), + default=date.today, + ) + equipment = models.ForeignKey( + Equipment, + related_name="losts", + help_text=_("Matériel concerné par la perte"), + ) + ids = IdField() + + class EquipmentRevision(models.Model): date = models.DateField( _("date"),