mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-06 22:58:19 -05:00
first ideas of property editor
This commit is contained in:
@@ -651,7 +651,7 @@ class IngredientSimpleSerializer(WritableNestedModelSerializer):
|
||||
uch = UnitConversionHelper(self.context['request'].space)
|
||||
conversions = []
|
||||
for c in uch.get_conversions(obj):
|
||||
conversions.append({'food': c.food.name, 'unit': c.unit.name , 'amount': c.amount}) # TODO do formatting in helper
|
||||
conversions.append({'food': c.food.name, 'unit': c.unit.name, 'amount': c.amount}) # TODO do formatting in helper
|
||||
return conversions
|
||||
else:
|
||||
return []
|
||||
@@ -726,7 +726,7 @@ class StepRecipeSerializer(WritableNestedModelSerializer):
|
||||
class UnitConversionSerializer(WritableNestedModelSerializer):
|
||||
base_unit = UnitSerializer()
|
||||
converted_unit = UnitSerializer()
|
||||
food = FoodSerializer(allow_null=True)
|
||||
food = FoodSerializer(allow_null=True, required=False)
|
||||
base_amount = CustomDecimalField()
|
||||
converted_amount = CustomDecimalField()
|
||||
|
||||
@@ -740,7 +740,7 @@ class UnitConversionSerializer(WritableNestedModelSerializer):
|
||||
fields = ('id', 'base_amount', 'base_unit', 'converted_amount', 'converted_unit', 'food')
|
||||
|
||||
|
||||
class NutritionTypeSerializer(serializers.ModelSerializer):
|
||||
class FoodPropertyTypeSerializer(serializers.ModelSerializer):
|
||||
def create(self, validated_data):
|
||||
validated_data['space'] = self.context['request'].space
|
||||
return super().create(validated_data)
|
||||
@@ -750,6 +750,22 @@ class NutritionTypeSerializer(serializers.ModelSerializer):
|
||||
fields = ('id', 'name', 'icon', 'unit', 'description')
|
||||
|
||||
|
||||
class FoodPropertySerializer(UniqueFieldsMixin, WritableNestedModelSerializer):
|
||||
property_type = FoodPropertyTypeSerializer()
|
||||
food = FoodSimpleSerializer()
|
||||
unit = UnitSerializer()
|
||||
# TODO prevent updates
|
||||
|
||||
def create(self, validated_data):
|
||||
validated_data['space'] = self.context['request'].space
|
||||
return super().create(validated_data)
|
||||
|
||||
class Meta:
|
||||
model = FoodProperty
|
||||
fields = ('id', 'food_amount', 'food_unit', 'food', 'property_amount', 'property_type')
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
class NutritionInformationSerializer(serializers.ModelSerializer):
|
||||
carbohydrates = CustomDecimalField()
|
||||
fats = CustomDecimalField()
|
||||
|
||||
@@ -269,6 +269,33 @@
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<a href="{% url 'list_food_property_type' %}" class="p-0 p-md-1">
|
||||
<div class="card p-0 no-gutters border-0">
|
||||
<div class="card-body text-center p-0 no-gutters">
|
||||
<i class="fas fa-database fa-2x"></i>
|
||||
</div>
|
||||
<div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
|
||||
{% trans 'Food Properties' %}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row m-0 mt-2 mt-md-0">
|
||||
<div class="col-4">
|
||||
<a href="{% url 'list_unit_conversion' %}" class="p-0 p-md-1">
|
||||
<div class="card p-0 no-gutters border-0">
|
||||
<div class="card-body text-center p-0 no-gutters">
|
||||
<i class="fas fa-exchange-alt fa-2x"></i>
|
||||
</div>
|
||||
<div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
|
||||
{% trans 'Unit Conversions' %}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
@@ -92,7 +92,7 @@ from cookbook.serializer import (AutomationSerializer, BookmarkletImportListSeri
|
||||
SyncLogSerializer, SyncSerializer, UnitSerializer,
|
||||
UserFileSerializer, UserSerializer, UserPreferenceSerializer,
|
||||
UserSpaceSerializer, ViewLogSerializer, AccessTokenSerializer, FoodSimpleSerializer,
|
||||
RecipeExportSerializer, UnitConversionSerializer, NutritionTypeSerializer)
|
||||
RecipeExportSerializer, UnitConversionSerializer, FoodPropertyTypeSerializer)
|
||||
from cookbook.views.import_export import get_integration
|
||||
from recipes import settings
|
||||
|
||||
@@ -971,7 +971,7 @@ class UnitConversionViewSet(viewsets.ModelViewSet):
|
||||
|
||||
class NutritionTypeViewSet(viewsets.ModelViewSet):
|
||||
queryset = FoodPropertyType.objects
|
||||
serializer_class = NutritionTypeSerializer
|
||||
serializer_class = FoodPropertyTypeSerializer
|
||||
permission_classes = [CustomIsUser & CustomTokenHasReadWriteScope]
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
Reference in New Issue
Block a user