cleanup views
This commit is contained in:
parent
e3921cd6a8
commit
763f71a05c
@ -724,12 +724,19 @@ class StepRecipeSerializer(WritableNestedModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class UnitConversionSerializer(WritableNestedModelSerializer):
|
class UnitConversionSerializer(WritableNestedModelSerializer):
|
||||||
|
name = serializers.SerializerMethodField('get_conversion_name')
|
||||||
base_unit = UnitSerializer()
|
base_unit = UnitSerializer()
|
||||||
converted_unit = UnitSerializer()
|
converted_unit = UnitSerializer()
|
||||||
food = FoodSerializer(allow_null=True, required=False)
|
food = FoodSerializer(allow_null=True, required=False)
|
||||||
base_amount = CustomDecimalField()
|
base_amount = CustomDecimalField()
|
||||||
converted_amount = CustomDecimalField()
|
converted_amount = CustomDecimalField()
|
||||||
|
|
||||||
|
def get_conversion_name(self, obj):
|
||||||
|
text = f'{round(obj.base_amount)} {obj.base_unit} '
|
||||||
|
if obj.food:
|
||||||
|
text += f' {obj.food}'
|
||||||
|
return text + f' = {round(obj.converted_amount)} {obj.converted_unit}'
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
validated_data['space'] = self.context['request'].space
|
validated_data['space'] = self.context['request'].space
|
||||||
validated_data['created_by'] = self.context['request'].user
|
validated_data['created_by'] = self.context['request'].user
|
||||||
@ -737,7 +744,7 @@ class UnitConversionSerializer(WritableNestedModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UnitConversion
|
model = UnitConversion
|
||||||
fields = ('id', 'base_amount', 'base_unit', 'converted_amount', 'converted_unit', 'food', 'open_data_slug')
|
fields = ('id', 'name','base_amount', 'base_unit', 'converted_amount', 'converted_unit', 'food', 'open_data_slug')
|
||||||
|
|
||||||
|
|
||||||
class FoodPropertyTypeSerializer(serializers.ModelSerializer):
|
class FoodPropertyTypeSerializer(serializers.ModelSerializer):
|
||||||
@ -747,7 +754,7 @@ class FoodPropertyTypeSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FoodPropertyType
|
model = FoodPropertyType
|
||||||
fields = ('id', 'name', 'icon', 'unit', 'description')
|
fields = ('id', 'name', 'icon', 'unit', 'description', 'open_data_slug')
|
||||||
|
|
||||||
|
|
||||||
class FoodPropertySerializer(UniqueFieldsMixin, WritableNestedModelSerializer):
|
class FoodPropertySerializer(UniqueFieldsMixin, WritableNestedModelSerializer):
|
||||||
|
@ -83,6 +83,10 @@
|
|||||||
"Update_Existing_Data": "Update Existing Data",
|
"Update_Existing_Data": "Update Existing Data",
|
||||||
"Use_Metric": "Use Metric Units",
|
"Use_Metric": "Use Metric Units",
|
||||||
"Learn_More": "Learn More",
|
"Learn_More": "Learn More",
|
||||||
|
"converted_unit": "Converted Unit",
|
||||||
|
"converted_amount": "Converted Amount",
|
||||||
|
"base_unit": "Base Unit",
|
||||||
|
"base_amount": "Base Amount",
|
||||||
"Datatype": "Datatype",
|
"Datatype": "Datatype",
|
||||||
"Number of Objects": "Number of Objects",
|
"Number of Objects": "Number of Objects",
|
||||||
"Add_Step": "Add Step",
|
"Add_Step": "Add Step",
|
||||||
|
@ -617,7 +617,7 @@ export class Models {
|
|||||||
field: "base_unit",
|
field: "base_unit",
|
||||||
list: "UNIT",
|
list: "UNIT",
|
||||||
list_label: "name",
|
list_label: "name",
|
||||||
label: "Base Unit",
|
label: "base_unit",
|
||||||
multiple: false,
|
multiple: false,
|
||||||
},
|
},
|
||||||
converted_amount: {
|
converted_amount: {
|
||||||
@ -633,7 +633,7 @@ export class Models {
|
|||||||
field: "converted_unit",
|
field: "converted_unit",
|
||||||
list: "UNIT",
|
list: "UNIT",
|
||||||
list_label: "name",
|
list_label: "name",
|
||||||
label: "Converted Unit",
|
label: "converted_unit",
|
||||||
multiple: false,
|
multiple: false,
|
||||||
},
|
},
|
||||||
food: {
|
food: {
|
||||||
@ -641,7 +641,7 @@ export class Models {
|
|||||||
type: "lookup",
|
type: "lookup",
|
||||||
field: "food",
|
field: "food",
|
||||||
list: "FOOD",
|
list: "FOOD",
|
||||||
list_label: "Food",
|
list_label: "name",
|
||||||
label: "Food",
|
label: "Food",
|
||||||
multiple: false,
|
multiple: false,
|
||||||
},
|
},
|
||||||
@ -671,7 +671,7 @@ export class Models {
|
|||||||
create: {
|
create: {
|
||||||
params: [['name', 'icon', 'unit', 'description']],
|
params: [['name', 'icon', 'unit', 'description']],
|
||||||
form: {
|
form: {
|
||||||
|
show_help: true,
|
||||||
name: {
|
name: {
|
||||||
form_field: true,
|
form_field: true,
|
||||||
type: "text",
|
type: "text",
|
||||||
@ -700,6 +700,14 @@ export class Models {
|
|||||||
label: "Description",
|
label: "Description",
|
||||||
placeholder: "",
|
placeholder: "",
|
||||||
},
|
},
|
||||||
|
open_data_slug: {
|
||||||
|
form_field: true,
|
||||||
|
type: "text",
|
||||||
|
field: "open_data_slug",
|
||||||
|
disabled: true,
|
||||||
|
label: "Open_Data_Slug",
|
||||||
|
help_text: "open_data_help_text",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user