gestiojeux/loans/models.py
Sylvain Gay 474083dd38 Add minimal loans system
Functional loans system for users.
No manager interface yet.

See:
- app "loans"
- a few new views/templates in app "inventory"
2024-05-02 11:13:34 +02:00

32 lines
933 B
Python

from django.db import models
from autoslug import AutoSlugField
from django.utils.timezone import now
class AbstractLoan(models.Model):
lent_object = None # Fill this with a foreign key in subclasses
slug = AutoSlugField(unique=True, populate_from="lent_object")
borrow_date = models.DateTimeField(auto_now_add=True)
return_date = models.DateTimeField(null=True)
mail = models.EmailField()
lent_object_slug_field = "slug"
class Meta:
ordering=["borrow_date"]
verbose_name = "emprunt"
verbose_name_plural = "emprunts"
def __str__(self):
return self.slug
def return_object(self):
self.return_date = now()
self.save()
@classmethod
def ongoing_loans(cls, obj = None):
ongoing = cls.objects.filter(return_date=None)
if obj != None:
return ongoing.filter(lent_object=obj)
else:
return ongoing