|
@@ -1,6 +1,7 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
+from django.core.exceptions import ValidationError
|
|
|
from django.db import models
|
|
|
from django.db.models import Q
|
|
|
from django.conf import settings
|
|
@@ -172,6 +173,18 @@ class Loan(models.Model):
|
|
|
is_running.boolean = True
|
|
|
is_running.short_description = 'En cours ?'
|
|
|
|
|
|
+ def clean(self):
|
|
|
+ current_loan = self.item.get_current_loan()
|
|
|
+ if (
|
|
|
+ self.is_running()
|
|
|
+ and
|
|
|
+ current_loan
|
|
|
+ and
|
|
|
+ self.item.get_current_loan() != self
|
|
|
+ ):
|
|
|
+ raise ValidationError(
|
|
|
+ "Il y a déjà un emprunt en cours sur cet objet")
|
|
|
+
|
|
|
class Meta:
|
|
|
verbose_name = 'prêt d’objet'
|
|
|
verbose_name_plural = 'prêts d’objets'
|