Override attribution save() + stuff
This commit is contained in:
parent
3439abe922
commit
8a587b3d56
2 changed files with 27 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from event.models import Activity
|
from event.models import Activity, EventSpecificMixin
|
||||||
from shared.models import EventSpecificMixin
|
|
||||||
|
|
||||||
|
|
||||||
class Equipment(EventSpecificMixin, models.Model):
|
class Equipment(EventSpecificMixin, models.Model):
|
||||||
|
@ -18,8 +18,8 @@ class Equipment(EventSpecificMixin, models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("matériel permanent")
|
verbose_name = _("matériel")
|
||||||
verbose_name_plural = _("matériels permanents")
|
verbose_name_plural = _("matériels")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -40,6 +40,12 @@ class EquipmentAttribution(models.Model):
|
||||||
self.amout,
|
self.amout,
|
||||||
self.activity.get_herited('title'))
|
self.activity.get_herited('title'))
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.equipment.event and self.equipment.event != self.activity.event:
|
||||||
|
raise ValidationError
|
||||||
|
|
||||||
|
super(EquipmentAttribution, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class EquipmentRemark(models.Model):
|
class EquipmentRemark(models.Model):
|
||||||
remark = models.TextField(_("remarque sur le matériel"))
|
remark = models.TextField(_("remarque sur le matériel"))
|
||||||
|
|
|
@ -4,7 +4,6 @@ from django.core.validators import RegexValidator
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from communication.models import SubscriptionMixin
|
from communication.models import SubscriptionMixin
|
||||||
from shared.models import EventSpecificMixin
|
|
||||||
|
|
||||||
|
|
||||||
class Event(SubscriptionMixin, models.Model):
|
class Event(SubscriptionMixin, models.Model):
|
||||||
|
@ -39,6 +38,23 @@ class Event(SubscriptionMixin, models.Model):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
|
class EventSpecificMixin(models.Model):
|
||||||
|
"""Mixin allowing for event-specific models instances
|
||||||
|
or not (depending on whether the event field is null)"""
|
||||||
|
|
||||||
|
event = models.ForeignKey(
|
||||||
|
'event.Event',
|
||||||
|
verbose_name=_("évènement"),
|
||||||
|
help_text=_("Si spécifié, l'instance du modèle "
|
||||||
|
"est spécifique à l'évènement en question"),
|
||||||
|
blank=True,
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class Place(EventSpecificMixin, models.Model):
|
class Place(EventSpecificMixin, models.Model):
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
_("nom du lieu"),
|
_("nom du lieu"),
|
||||||
|
|
Loading…
Reference in a new issue