med/users/models.py

64 lines
1.8 KiB
Python
Raw Normal View History

2019-08-02 12:57:53 +00:00
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
2019-08-08 10:16:40 +00:00
from django.contrib.auth.models import AbstractUser
2019-08-02 12:57:53 +00:00
from django.db import models
from django.utils import timezone
2019-08-02 12:57:53 +00:00
from django.utils.translation import gettext_lazy as _
2019-08-09 21:17:55 +00:00
from med.settings import MAX_EMPRUNT
2019-08-08 10:16:40 +00:00
class User(AbstractUser):
telephone = models.CharField(
verbose_name=_('phone number'),
max_length=15,
null=True,
blank=True,
2019-08-02 19:35:30 +00:00
)
2019-08-08 10:16:40 +00:00
address = models.CharField(
verbose_name=_('address'),
max_length=255,
null=True,
blank=True,
2019-08-02 16:37:54 +00:00
)
2019-08-08 10:16:40 +00:00
maxemprunt = models.IntegerField(
verbose_name=_('maximum borrowed'),
2019-08-08 13:35:25 +00:00
help_text=_('Maximal amount of simultaneous borrowed item '
'authorized.'),
2019-08-08 10:16:40 +00:00
default=MAX_EMPRUNT,
)
comment = models.CharField(
verbose_name=_('comment'),
help_text=_('Promotion...'),
max_length=255,
blank=True,
2019-08-02 16:37:54 +00:00
)
date_joined = models.DateTimeField(
_('date joined'),
default=timezone.now,
null=True,
)
2019-08-08 10:16:40 +00:00
REQUIRED_FIELDS = ['first_name', 'last_name', 'email']
@property
def is_adherent(self):
2019-08-08 13:35:25 +00:00
last_adh_year = Adhesion.objects.all().order_by(
'annee_debut').reverse().first()
2019-08-02 19:35:30 +00:00
return last_adh_year and self in last_adh_year.adherent.all()
2017-07-03 18:06:21 +00:00
class Clef(models.Model):
nom = models.CharField(max_length=255, unique=True)
2019-08-08 13:35:25 +00:00
proprio = models.ForeignKey('User', on_delete=models.PROTECT, blank=True,
null=True)
2017-07-03 18:06:21 +00:00
commentaire = models.CharField(max_length=255, null=True, blank=True)
2019-08-02 12:57:53 +00:00
class Adhesion(models.Model):
annee_debut = models.IntegerField(unique=True)
annee_fin = models.IntegerField(unique=True)
adherent = models.ManyToManyField('User', blank=True)