diff --git a/equipement/__init__.py b/equipement/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/equipement/admin.py b/equipement/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/equipement/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/equipement/apps.py b/equipement/apps.py new file mode 100644 index 0000000..7d172de --- /dev/null +++ b/equipement/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class EquipementConfig(AppConfig): + name = 'equipement' diff --git a/equipement/models.py b/equipement/models.py new file mode 100644 index 0000000..70ad3e8 --- /dev/null +++ b/equipement/models.py @@ -0,0 +1,73 @@ +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +from event.models import Event, Activity + + +class AbstractEquipement(models.Model): + name = models.CharField( + _("Nom du matériel"), + max_length=200, + ) + stock = models.PositieSmallIntegerField(_("Quantité disponible")) + description = models.TextField(_("Description")) + + class Meta: + verbose_name = _("matériel abstrait") + verbose_name_plural = _("matériels abstraits") + + def __str__(self): + return self.name + + +class Equipement(AbstractEquipement): + class Meta: + verbose_name = _("matériel permanent") + verbose_name_plural = _("matériels permanents") + + +class TemporaryEquipement(AbstractEquipement): + event = models.ForeignKey( + Event, + related_name="specific_equipement", + 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 EquipementAttribution(models.Model): + equipement = models.ForeignKey(AbstractEquipement) + 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.equipement.name +\ + " (" + self.amout + ") " +\ + " -> " + self.activity.get_herited('title') + + +class EquipementRemark(models.Model): + remark = models.TextField("Remarque sur le matériel") + equipement = models.ForeignKey( + AbstractEquipement, + 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.equipement.name + " : " + self.remark diff --git a/equipement/tests.py b/equipement/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/equipement/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/equipement/views.py b/equipement/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/equipement/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/event/models.py b/event/models.py index a688096..7f51971 100644 --- a/event/models.py +++ b/event/models.py @@ -4,6 +4,8 @@ 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): @@ -157,7 +159,11 @@ class Activity(ActivityTemplate): related_name="in_perm_activities", blank=True, ) - # equipement = models.ManyToManyField(Equipement) + equipement = models.ManyToManyField( + AbstractEquipement, + related_name="activities", + through="EquipementAttribution", + ) def get_herited(self, attrname): attr = super(Activity, self).__getattribute__(attrname)