|
@@ -61,6 +61,18 @@ class Item(models.Model):
|
|
self.loans.filter(loan_date_end=None).update(loan_date_end=date.today())
|
|
self.loans.filter(loan_date_end=None).update(loan_date_end=date.today())
|
|
|
|
|
|
|
|
|
|
|
|
+class LoanQuerySet(models.QuerySet):
|
|
|
|
+ running_filter = (
|
|
|
|
+ models.Q(loan_date_end__gt=date.today()) |
|
|
|
|
+ models.Q(loan_date_end__isnull=True))
|
|
|
|
+
|
|
|
|
+ def running(self):
|
|
|
|
+ return self.filter(self.running_filter)
|
|
|
|
+
|
|
|
|
+ def finished(self):
|
|
|
|
+ return self.exclude(self.running_filter)
|
|
|
|
+
|
|
|
|
+
|
|
class Loan(models.Model):
|
|
class Loan(models.Model):
|
|
item = models.ForeignKey(Item, verbose_name='objet', related_name='loans')
|
|
item = models.ForeignKey(Item, verbose_name='objet', related_name='loans')
|
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='membre',
|
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='membre',
|
|
@@ -78,3 +90,5 @@ class Loan(models.Model):
|
|
class Meta:
|
|
class Meta:
|
|
verbose_name = 'prêt d’objet'
|
|
verbose_name = 'prêt d’objet'
|
|
verbose_name_plural = 'prêts d’objets'
|
|
verbose_name_plural = 'prêts d’objets'
|
|
|
|
+
|
|
|
|
+ objects = LoanQuerySet().as_manager()
|