poulpe/equipment/models.py

79 lines
2.5 KiB
Python
Raw Normal View History

2016-10-14 13:02:25 +02:00
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(
2017-07-15 17:44:15 +02:00
_("nom du matériel"),
2016-10-14 13:02:25 +02:00
max_length=200,
)
2017-07-15 17:44:15 +02:00
stock = models.PositiveSmallIntegerField(_("quantité disponible"))
description = models.TextField(_("description"))
2016-10-14 13:02:25 +02:00
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 "
2016-10-21 18:49:46 +02:00
"a été loué ou emprunté ou apporté"),
2016-10-14 13:02:25 +02:00
)
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)
2017-07-15 17:44:15 +02:00
amount = models.PositiveSmallIntegerField(_("quantité attribuée"))
remarks = models.TextField(_("remarques concernant l'attribution"))
2016-10-14 13:02:25 +02:00
class Meta:
verbose_name = _("attribution de matériel")
verbose_name_plural = _("attributions de matériel")
def __str__(self):
2016-10-21 18:49:46 +02:00
return "%s (%d) -> %s" % (self.equipment.name,
self.amout,
self.activity.get_herited('title'))
2016-10-14 13:02:25 +02:00
class EquipmentRemark(models.Model):
2017-07-15 17:44:15 +02:00
remark = models.TextField(_("remarque sur le matériel"))
2016-10-14 13:02:25 +02:00
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):
2016-10-21 18:49:46 +02:00
return "%s : %s" % (self.equipment.name,
self.remark)