From 3c93b0fa23ad61ec0b5538253a628f1688998781 Mon Sep 17 00:00:00 2001 From: Qwann Date: Fri, 14 Oct 2016 13:02:25 +0200 Subject: [PATCH] models de equipment done --- equipment/apps.py | 5 +++ equipment/migrations/__init__.py | 0 equipment/models.py | 77 ++++++++++++++++++++++++++++++++ event/migrations/__init__.py | 0 event/models.py | 11 +---- 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 equipment/apps.py create mode 100644 equipment/migrations/__init__.py create mode 100644 equipment/models.py create mode 100644 event/migrations/__init__.py diff --git a/equipment/apps.py b/equipment/apps.py new file mode 100644 index 0000000..ac98343 --- /dev/null +++ b/equipment/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class EquipmentConfig(AppConfig): + name = 'equipment' diff --git a/equipment/migrations/__init__.py b/equipment/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/equipment/models.py b/equipment/models.py new file mode 100644 index 0000000..d662367 --- /dev/null +++ b/equipment/models.py @@ -0,0 +1,77 @@ +from django.db import models +from django.utils.translation import ugettext_lazy as _ +from event.models import Event, Activity + + +class AbstractEquipment(models.Model): + name = models.CharField( + _("Nom du matériel"), + max_length=200, + ) + stock = models.PositiveSmallIntegerField(_("Quantité disponible")) + description = models.TextField(_("Description")) + activities = models.ManyToManyField( + Activity, + related_name="equipment", + through="EquipmentAttribution", + ) + + class Meta: + verbose_name = _("matériel abstrait") + verbose_name_plural = _("matériels abstraits") + + def __str__(self): + return self.name + + +class Equipment(AbstractEquipment): + class Meta: + verbose_name = _("matériel permanent") + verbose_name_plural = _("matériels permanents") + + +class TemporaryEquipment(AbstractEquipment): + event = models.ForeignKey( + Event, + related_name="specific_equipment", + help_text=_("Évènement pour lequel le matériel " + "a été loué ou empreinté ou apporté"), + ) + + class Meta: + verbose_name = _("matériel temporaire") + verbose_name_plural = _("matériels temporaires") + + +class EquipmentAttribution(models.Model): + equipment = models.ForeignKey(AbstractEquipment) + activity = models.ForeignKey(Activity) + amount = models.PositiveSmallIntegerField(_("Quantité attribuée")) + remarks = models.TextField("Remarques concernant l'attribution") + + class Meta: + verbose_name = _("attribution de matériel") + verbose_name_plural = _("attributions de matériel") + + def __str__(self): + return self.equipment.name +\ + " (" + self.amout + ") " +\ + " -> " + self.activity.get_herited('title') + + +class EquipmentRemark(models.Model): + remark = models.TextField("Remarque sur le matériel") + equipment = models.ForeignKey( + AbstractEquipment, + related_name="remarks", + help_text=_("Matériel concerné par la remarque"), + ) + is_broken = models.BooleanField() + is_lost = models.BooleanField() + + class Meta: + verbose_name = _("remarque sur matériel") + verbose_name_plural = _("remarques sur le matériel") + + def __str__(self): + return self.equipment.name + " : " + self.remark diff --git a/event/migrations/__init__.py b/event/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/event/models.py b/event/models.py index 2d9d56a..87766e4 100644 --- a/event/models.py +++ b/event/models.py @@ -4,8 +4,6 @@ from django.core import exceptions from django.db import models from re import search as re_search -from equipement.models import AbstractEquipement - def validate_color(value): def is_hex_color(s): @@ -159,17 +157,12 @@ class Activity(ActivityTemplate): related_name="in_perm_activities", blank=True, ) - equipement = models.ManyToManyField( - AbstractEquipement, - related_name="activities", - through="EquipementAttribution", - ) def get_herited(self, attrname): attr = super(Activity, self).__getattribute__(attrname) if (attrname == 'parent' or attrname == 'staff' - or attrname == 'equipement'): + or attrname == 'equipment'): return attr elif (attrname == 'place' or attrname == 'tags'): if attr.exists(): @@ -194,7 +187,7 @@ class Activity(ActivityTemplate): # attr = super(Activity, self).__getattribute__(attrname) # if (attrname == 'parent' # or attrname == 'staff' - # or attrname == 'equipement'): + # or attrname == 'equipment'): # return attr # elif attr is None: # return self.parent.__getattribute__(attrname)