generated from 2martens/django-template
154 lines
6.5 KiB
Python
154 lines
6.5 KiB
Python
# coding=utf-8
|
|
from django.contrib.auth.models import User
|
|
from django.db import models
|
|
from django.utils.text import format_lazy
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
MEASUREMENT_UNITS = [('KG', 'kg'),
|
|
('G', 'g'),
|
|
('MG', 'mg'),
|
|
('L', 'l'),
|
|
('ML', 'ml'),
|
|
('TEA', _('teaspoon')),
|
|
('TBL', _('tablespoon')),
|
|
('PINCH', _('pinch')),
|
|
('PIECE', _('piece'))]
|
|
|
|
|
|
class Profile(models.Model):
|
|
user = models.OneToOneField(User, models.CASCADE)
|
|
daily_fat_demand = models.PositiveIntegerField(_('Daily fat demand'),
|
|
help_text=_('At most this amount of fat is needed per day'),
|
|
default=117)
|
|
daily_carbohydrate_demand = models.PositiveIntegerField(
|
|
_('Daily carbohydrate demand'),
|
|
help_text=_('At most this amount of carbohydrates is needed per day'),
|
|
default=150)
|
|
daily_sugar_demand = models.PositiveIntegerField(_('Daily sugar demand'),
|
|
help_text=_('At most this amount of sugar is needed per day'),
|
|
default=25)
|
|
daily_roughage_demand = models.PositiveIntegerField(
|
|
_('Daily roughage demand'),
|
|
help_text=_('At least this amount of roughage should be eaten per day'),
|
|
default=30)
|
|
daily_protein_demand = models.PositiveIntegerField(
|
|
_('Daily protein demand'),
|
|
help_text=_('At most this amount of protein should be eaten per day'),
|
|
default=90)
|
|
|
|
def __str__(self):
|
|
return self.user.username
|
|
|
|
|
|
class KitchenUtility(models.Model):
|
|
name = models.CharField(_('Name'), max_length=255)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Ingredient(models.Model):
|
|
name = models.CharField(_('Name'), max_length=255)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Recipe(models.Model):
|
|
author = models.ForeignKey(User, models.SET_NULL, null=True)
|
|
kitchen_utilities = models.ManyToManyField(KitchenUtility,
|
|
through='UsedKitchenUtilities')
|
|
ingredients = models.ManyToManyField(Ingredient, through='UsedIngredient')
|
|
|
|
name = models.CharField(_('Name'), max_length=255)
|
|
image = models.ImageField(_('Image'), blank=True, null=True)
|
|
experience_level = models.CharField(_('Required cooking experience'), max_length=255,
|
|
choices=[
|
|
('NOV', _('Novice')),
|
|
('INT', _('Intermediate')),
|
|
('ADV', _('Advanced')),
|
|
('EXP', _('Expert'))
|
|
])
|
|
|
|
fat = models.PositiveIntegerField(_('Fat'),
|
|
help_text=_('How much fat does one portion contain?'))
|
|
carbohydrates = models.PositiveIntegerField(_('Carbohydrates'),
|
|
help_text=_('How much carbohydrates does one portion contain?'))
|
|
sugar = models.PositiveIntegerField(_('Sugar'),
|
|
help_text=_('How much sugar does one portion contain?'))
|
|
roughage = models.PositiveIntegerField(_('Roughage'),
|
|
help_text=_('How much roughage does one portion contain?'))
|
|
protein = models.PositiveIntegerField(_('Protein'),
|
|
help_text=_('How much protein does one portion contain?'))
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class RecipeStep(models.Model):
|
|
recipe = models.ForeignKey(Recipe, models.CASCADE)
|
|
image = models.ImageField(_('Image'), blank=True, null=True)
|
|
description = models.TextField(_('Description'))
|
|
number_of_step = models.PositiveIntegerField(_('Number of step'))
|
|
|
|
class Meta:
|
|
unique_together = ['recipe', 'number_of_step']
|
|
|
|
|
|
class UsedKitchenUtilities(models.Model):
|
|
recipe = models.ForeignKey(Recipe, models.CASCADE)
|
|
kitchen_utility = models.ForeignKey(KitchenUtility, models.CASCADE)
|
|
amount = models.PositiveIntegerField(_('Amount'),
|
|
help_text=_('How often is this kitchen utility used?'),
|
|
default=1)
|
|
|
|
|
|
class UsedIngredient(models.Model):
|
|
recipe = models.ForeignKey(Recipe, models.CASCADE)
|
|
ingredient = models.ForeignKey(Ingredient, models.CASCADE)
|
|
amount = models.PositiveIntegerField(_('Amount'),
|
|
help_text=_('Please specify the used amount of the ingredient'))
|
|
unit = models.CharField(_('Unit for amount'), max_length=10, choices=MEASUREMENT_UNITS)
|
|
|
|
|
|
class Vendor(models.Model):
|
|
name = models.CharField(_('Vendor'), max_length=50)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Product(models.Model):
|
|
name = models.CharField(_('Product'), max_length=255)
|
|
vendor = models.ForeignKey(Vendor, models.CASCADE)
|
|
ingredient = models.ForeignKey(Ingredient, models.SET_NULL, null=True)
|
|
amount = models.PositiveIntegerField(_('Amount'),
|
|
help_text=_('Please specify the provided amount of the ingredient'))
|
|
unit = models.CharField(_('Unit for amount'), max_length=10,
|
|
choices=MEASUREMENT_UNITS)
|
|
price = models.DecimalField(_('Price'), decimal_places=2, max_digits=4,
|
|
blank=True, default=0.0)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Pantry(models.Model):
|
|
owner = models.ForeignKey(User, models.CASCADE)
|
|
ingredients = models.ManyToManyField(Ingredient, through='StoredIngredients')
|
|
|
|
def __str__(self):
|
|
return format_lazy('Pantry of {firstName} {lastName}',
|
|
firstName=self.owner.first_name,
|
|
lastName=self.owner.last_name)
|
|
|
|
|
|
class StoredIngredients(models.Model):
|
|
pantry = models.ForeignKey(Pantry, models.CASCADE)
|
|
ingredient = models.ForeignKey(Ingredient, models.CASCADE)
|
|
amount = models.PositiveIntegerField(_('Amount'),
|
|
help_text=_('Please specify the stored amount of the ingredient'))
|
|
unit = models.CharField(_('Unit for amount'), max_length=10,
|
|
choices=MEASUREMENT_UNITS)
|