1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-23 07:52:23 +00:00

Création de l'apps et de la base de donnée

This commit is contained in:
quark 2024-05-17 20:46:38 +02:00 committed by korenstin
parent 74de358953
commit 9e6342c929
9 changed files with 368 additions and 0 deletions

0
apps/food/__init__.py Normal file
View File

3
apps/food/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
apps/food/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class FoodkfetConfig(AppConfig):
name = 'foodkfet'

View File

@ -0,0 +1,96 @@
# Generated by Django 2.2.28 on 2024-05-17 18:44
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('member', '0011_profile_vss_charter_read'),
]
operations = [
migrations.CreateModel(
name='Allergen',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('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')),
],
options={
'verbose_name': 'Allergen',
'verbose_name_plural': 'Allergens',
},
),
migrations.CreateModel(
name='Basic_food',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, verbose_name='name')),
('is_DLC', models.BooleanField(default=False, verbose_name='is DLC')),
('is_DDM', models.BooleanField(default=False, verbose_name='is DDM')),
('expiry_date', models.DateTimeField(blank=True, default=django.utils.timezone.now, verbose_name='expiry date')),
('label', models.ImageField(default='pic/default.png', max_length=255, upload_to='label/', verbose_name='food label')),
('was_eaten', models.BooleanField(default=False, verbose_name='was eaten')),
('allergen', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='food.Allergen', verbose_name='allergen')),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='owner')),
],
options={
'verbose_name': 'Basic food',
'verbose_name_plural': 'Basic foods',
},
),
migrations.CreateModel(
name='QR_code',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('qr_code_number', models.PositiveIntegerField(verbose_name='QR-code number')),
],
options={
'verbose_name': 'QR-code',
'verbose_name_plural': 'QR-codes',
},
),
migrations.CreateModel(
name='Transformed_food',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('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')),
('is_active', models.BooleanField(default=True, verbose_name='is active')),
('was_eaten', models.BooleanField(default=False, verbose_name='was eaten')),
('allergen', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='food.Allergen', verbose_name='allergen')),
('basic_ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='food.Basic_food', verbose_name='basic ingredient')),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='owner')),
('qr_code', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='food.QR_code', verbose_name='QR code')),
('transformed_ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='food.Transformed_food', verbose_name='transformed ingredient')),
],
options={
'verbose_name': 'Transformed food',
'verbose_name_plural': 'Transformed foods',
},
),
migrations.AddField(
model_name='basic_food',
name='qr_code',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='food.QR_code', verbose_name='QR code'),
),
]

View File

257
apps/food/models.py Normal file
View File

@ -0,0 +1,257 @@
# 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

3
apps/food/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
apps/food/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -77,6 +77,7 @@ INSTALLED_APPS = [
'scripts',
'treasury',
'wei',
'food',
]
MIDDLEWARE = [