fixed allow decimals in food property amount
This commit is contained in:
parent
dcc56fc138
commit
436158f596
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.1.9 on 2023-06-26 13:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cookbook', '0193_space_internal_note'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='food',
|
||||||
|
name='properties_food_amount',
|
||||||
|
field=models.DecimalField(blank=True, decimal_places=2, default=100, max_digits=16),
|
||||||
|
),
|
||||||
|
]
|
@ -585,7 +585,7 @@ class Food(ExportModelOperationsMixin('food'), TreeModel, PermissionModelMixin):
|
|||||||
child_inherit_fields = models.ManyToManyField(FoodInheritField, blank=True, related_name='child_inherit')
|
child_inherit_fields = models.ManyToManyField(FoodInheritField, blank=True, related_name='child_inherit')
|
||||||
|
|
||||||
properties = models.ManyToManyField("Property", blank=True, through='FoodProperty')
|
properties = models.ManyToManyField("Property", blank=True, through='FoodProperty')
|
||||||
properties_food_amount = models.IntegerField(default=100, blank=True)
|
properties_food_amount = models.DecimalField(default=100, max_digits=16, decimal_places=2, blank=True)
|
||||||
properties_food_unit = models.ForeignKey(Unit, on_delete=models.PROTECT, blank=True, null=True)
|
properties_food_unit = models.ForeignKey(Unit, on_delete=models.PROTECT, blank=True, null=True)
|
||||||
|
|
||||||
preferred_unit = models.ForeignKey(Unit, on_delete=models.SET_NULL, null=True, blank=True, default=None, related_name='preferred_unit')
|
preferred_unit = models.ForeignKey(Unit, on_delete=models.SET_NULL, null=True, blank=True, default=None, related_name='preferred_unit')
|
||||||
|
@ -109,7 +109,7 @@ class CustomDecimalField(serializers.Field):
|
|||||||
if data == '':
|
if data == '':
|
||||||
return 0
|
return 0
|
||||||
try:
|
try:
|
||||||
return float(data.replace(',', ''))
|
return float(data.replace(',', '.'))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValidationError('A valid number is required')
|
raise ValidationError('A valid number is required')
|
||||||
|
|
||||||
@ -582,6 +582,7 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer, ExtendedR
|
|||||||
|
|
||||||
properties = PropertySerializer(many=True, allow_null=True, required=False)
|
properties = PropertySerializer(many=True, allow_null=True, required=False)
|
||||||
properties_food_unit = UnitSerializer(allow_null=True, required=False)
|
properties_food_unit = UnitSerializer(allow_null=True, required=False)
|
||||||
|
properties_food_amount = CustomDecimalField()
|
||||||
|
|
||||||
recipe_filter = 'steps__ingredients__food'
|
recipe_filter = 'steps__ingredients__food'
|
||||||
images = ['recipe__image']
|
images = ['recipe__image']
|
||||||
|
@ -471,10 +471,10 @@ export interface Food {
|
|||||||
properties?: Array<FoodProperties> | null;
|
properties?: Array<FoodProperties> | null;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @type {number}
|
* @type {string}
|
||||||
* @memberof Food
|
* @memberof Food
|
||||||
*/
|
*/
|
||||||
properties_food_amount?: number;
|
properties_food_amount: string;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @type {FoodPropertiesFoodUnit}
|
* @type {FoodPropertiesFoodUnit}
|
||||||
@ -1112,10 +1112,10 @@ export interface IngredientFood {
|
|||||||
properties?: Array<FoodProperties> | null;
|
properties?: Array<FoodProperties> | null;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @type {number}
|
* @type {string}
|
||||||
* @memberof IngredientFood
|
* @memberof IngredientFood
|
||||||
*/
|
*/
|
||||||
properties_food_amount?: number;
|
properties_food_amount: string;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @type {FoodPropertiesFoodUnit}
|
* @type {FoodPropertiesFoodUnit}
|
||||||
|
Loading…
Reference in New Issue
Block a user