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