mirror of https://gitlab.crans.org/bde/nk20
258 lines
5.6 KiB
Python
258 lines
5.6 KiB
Python
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from datetime import date
|
|
|
|
from django.conf import settings
|
|
from django.contrib.auth.models import User
|
|
from django.core.exceptions import ValidationError
|
|
from django.core.validators import MinValueValidator
|
|
from django.db import models
|
|
from django.db.models import Q
|
|
from django.utils import timezone
|
|
from django.utils.translation import gettext_lazy as _
|
|
from member.models import Club
|
|
|
|
|
|
class QR_code(models.Model):
|
|
"""
|
|
An QR_code model
|
|
"""
|
|
qr_code_number = models.PositiveIntegerField(
|
|
verbose_name=_("QR-code number"),
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _("QR-code")
|
|
verbose_name_plural = _("QR-codes")
|
|
|
|
def __str__(self):
|
|
return _("QR-code number {qr_code_number}").format(qr_code_number=self.qr_code_number)
|
|
|
|
class Allergen(models.Model):
|
|
"""
|
|
A list of allergen and alimentary restrictions
|
|
"""
|
|
|
|
gluten = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('gluten'),
|
|
)
|
|
|
|
nut = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('nut'),
|
|
)
|
|
|
|
crustecean = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('crustacean'),
|
|
)
|
|
|
|
celery = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('celery'),
|
|
)
|
|
|
|
egg = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('egg'),
|
|
)
|
|
|
|
mustard = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('mustard'),
|
|
)
|
|
|
|
fish = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('fish'),
|
|
)
|
|
|
|
soy = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('soy'),
|
|
)
|
|
|
|
milk = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('milk'),
|
|
)
|
|
|
|
sulphite = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('sulphite'),
|
|
)
|
|
|
|
lupine = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('lupine'),
|
|
)
|
|
|
|
mollusc = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('mollusc'),
|
|
)
|
|
|
|
groundnut = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('groundnut'),
|
|
)
|
|
|
|
sesame = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('sesame'),
|
|
)
|
|
|
|
alcohol = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('alcohol'),
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _('Allergen')
|
|
verbose_name_plural = _('Allergens')
|
|
|
|
def __str__(self):
|
|
return _('Allergens of #{id}').format(id=self.id)
|
|
|
|
|
|
class Basic_food(models.Model):
|
|
"""
|
|
Food which has been directly buy on supermarket
|
|
"""
|
|
name = models.CharField(
|
|
verbose_name=_('name'),
|
|
max_length=255,
|
|
)
|
|
|
|
is_DLC = models.BooleanField(
|
|
verbose_name=_("is DLC"),
|
|
default=False,
|
|
)
|
|
|
|
is_DDM = models.BooleanField(
|
|
verbose_name=_("is DDM"),
|
|
default=False,
|
|
)
|
|
|
|
expiry_date = models.DateTimeField(
|
|
verbose_name=_('expiry date'),
|
|
default=timezone.now,
|
|
blank=True,
|
|
)
|
|
|
|
owner = models.ForeignKey(
|
|
Club,
|
|
on_delete=models.PROTECT,
|
|
related_name= '+',
|
|
verbose_name=_('owner'),
|
|
)
|
|
|
|
label = models.ImageField(
|
|
verbose_name=_('food label'),
|
|
max_length=255,
|
|
blank=False,
|
|
null=False,
|
|
upload_to='label/',
|
|
default= 'pic/default.png',
|
|
)
|
|
|
|
qr_code = models.ForeignKey(
|
|
QR_code,
|
|
on_delete=models.PROTECT,
|
|
related_name= '+',
|
|
verbose_name=_('QR code'),
|
|
)
|
|
|
|
was_eaten = models.BooleanField(
|
|
verbose_name=_('was eaten'),
|
|
default = False,
|
|
)
|
|
|
|
allergen = models.ForeignKey(
|
|
Allergen,
|
|
on_delete = models.PROTECT,
|
|
related_name = '+',
|
|
verbose_name = _('allergen'),
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name=_('Basic food')
|
|
verbose_name_plural=_('Basic foods')
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
class Transformed_food(models.Model):
|
|
"""
|
|
Transformed food are a mix between basic food and meal
|
|
"""
|
|
name = models.CharField(
|
|
max_length = 255,
|
|
verbose_name =_('name'),
|
|
)
|
|
|
|
creation_date = models.DateTimeField(
|
|
verbose_name =_('creation date'),
|
|
)
|
|
|
|
expiry_date = models.DateTimeField(
|
|
verbose_name =_('expiry date'),
|
|
)
|
|
|
|
owner = models.ForeignKey(
|
|
Club,
|
|
on_delete = models.PROTECT,
|
|
related_name = '+',
|
|
verbose_name =_('owner'),
|
|
)
|
|
|
|
transformed_ingredient = models.ForeignKey(
|
|
"self",
|
|
on_delete = models.CASCADE,
|
|
related_name = '+',
|
|
verbose_name = _('transformed ingredient'),
|
|
)
|
|
|
|
basic_ingredient = models.ForeignKey(
|
|
Basic_food,
|
|
on_delete = models.CASCADE,
|
|
related_name = '+',
|
|
verbose_name = _('basic ingredient'),
|
|
)
|
|
|
|
|
|
is_active = models.BooleanField(
|
|
default = True,
|
|
verbose_name = _('is active'),
|
|
)
|
|
|
|
qr_code = models.ForeignKey(
|
|
QR_code,
|
|
on_delete = models.CASCADE,
|
|
related_name = '+',
|
|
verbose_name = _('QR code'),
|
|
)
|
|
|
|
was_eaten = models.BooleanField(
|
|
default = False,
|
|
verbose_name = _('was eaten'),
|
|
)
|
|
|
|
allergen = models.ForeignKey(
|
|
Allergen,
|
|
on_delete = models.PROTECT,
|
|
related_name= '+',
|
|
verbose_name = _('allergen'),
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _('Transformed food')
|
|
verbose_name_plural = _('Transformed foods')
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|