mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-12-25 18:22:24 +00:00
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
# -*- mode: python; coding: utf-8 -*-
|
|
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from django.contrib.auth.models import AbstractUser
|
|
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from med.settings import MAX_EMPRUNT
|
|
|
|
|
|
class User(AbstractUser):
|
|
telephone = models.CharField(
|
|
verbose_name=_('phone number'),
|
|
max_length=15,
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
address = models.CharField(
|
|
verbose_name=_('address'),
|
|
max_length=255,
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
maxemprunt = models.IntegerField(
|
|
verbose_name=_('maximum borrowed'),
|
|
help_text=_('Maximal amount of simultaneous borrowed item '
|
|
'authorized.'),
|
|
default=MAX_EMPRUNT,
|
|
)
|
|
comment = models.CharField(
|
|
verbose_name=_('comment'),
|
|
help_text=_('Promotion...'),
|
|
max_length=255,
|
|
blank=True,
|
|
)
|
|
|
|
REQUIRED_FIELDS = ['first_name', 'last_name', 'email']
|
|
|
|
@property
|
|
def is_adherent(self):
|
|
last_adh_year = Adhesion.objects.all().order_by(
|
|
'annee_debut').reverse().first()
|
|
return last_adh_year and self in last_adh_year.adherent.all()
|
|
|
|
|
|
class Clef(models.Model):
|
|
nom = models.CharField(max_length=255, unique=True)
|
|
proprio = models.ForeignKey('User', on_delete=models.PROTECT, blank=True,
|
|
null=True)
|
|
commentaire = models.CharField(max_length=255, null=True, blank=True)
|
|
|
|
|
|
class Adhesion(models.Model):
|
|
annee_debut = models.IntegerField(unique=True)
|
|
annee_fin = models.IntegerField(unique=True)
|
|
adherent = models.ManyToManyField('User', blank=True)
|