fixed allow decimals in food property amount

This commit is contained in:
vabene1111 2023-06-26 15:47:44 +02:00
parent dcc56fc138
commit 436158f596
4 changed files with 25 additions and 6 deletions

View File

@ -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),
),
]

View File

@ -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')

View File

@ -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']

View File

@ -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}