diff --git a/back/backend/policy.py b/back/backend/policy.py index d40f56e..e325284 100644 --- a/back/backend/policy.py +++ b/back/backend/policy.py @@ -61,6 +61,7 @@ flight_section = Section( "departure_date": {"label": "Departure date", "type": "date"}, "return_date": {"label": "Return date", "type": "date"}, "fare": {"label": "Fare", "type": "decimal"}, + "layovers": {"label": "Transit wait", "type": "integer"}, } ) diff --git a/back/backend/views.py b/back/backend/views.py index b04e358..3ef2682 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -49,13 +49,16 @@ def get_fields(s_id): # create dict of arrays for fields field_set = {"fields": []} queryset = Field.objects.filter(section_id=s_id).order_by('number') + for i in queryset: + # function to print corresponding datatype + key, value = get_datatype(i) data = { "field_name": i.field_name, "label": i.label, "type": i.type, "number": i.number, - "value": "i.to_json()", + key: value } # append the fields to array # use copy() to avoid overwriting @@ -63,6 +66,29 @@ def get_fields(s_id): return field_set +# function to convert value into JSON +def to_json(convert): + return {"value": convert} + +# function that gets corresponding +# data type +def get_datatype(self): + if self.type == "boolean": + if self.data_bool: + return "data_bool", True + else: + return "data_bool", False + elif self.type == "decimal": + return "decimal", self.data_decimal + elif self.type == "date": + return "date", "{}".format(self.data_date) + elif self.type == "file": + return "file", "{}".format(self.data_file) + elif self.type == "string": + return "string", "{}".format(self.data_string) + elif self.type == "integer": + return "integer", self.data_integer + # API Endpoints @api_view(['POST']) diff --git a/back/db.sqlite3 b/back/db.sqlite3 index fe3ce3e..9b7a3db 100644 Binary files a/back/db.sqlite3 and b/back/db.sqlite3 differ