added function that displays data values
This commit is contained in:
parent
9552589e24
commit
f19781a682
3 changed files with 28 additions and 1 deletions
|
@ -61,6 +61,7 @@ flight_section = Section(
|
||||||
"departure_date": {"label": "Departure date", "type": "date"},
|
"departure_date": {"label": "Departure date", "type": "date"},
|
||||||
"return_date": {"label": "Return date", "type": "date"},
|
"return_date": {"label": "Return date", "type": "date"},
|
||||||
"fare": {"label": "Fare", "type": "decimal"},
|
"fare": {"label": "Fare", "type": "decimal"},
|
||||||
|
"layovers": {"label": "Transit wait", "type": "integer"},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,16 @@ def get_fields(s_id):
|
||||||
# create dict of arrays for fields
|
# create dict of arrays for fields
|
||||||
field_set = {"fields": []}
|
field_set = {"fields": []}
|
||||||
queryset = Field.objects.filter(section_id=s_id).order_by('number')
|
queryset = Field.objects.filter(section_id=s_id).order_by('number')
|
||||||
|
|
||||||
for i in queryset:
|
for i in queryset:
|
||||||
|
# function to print corresponding datatype
|
||||||
|
key, value = get_datatype(i)
|
||||||
data = {
|
data = {
|
||||||
"field_name": i.field_name,
|
"field_name": i.field_name,
|
||||||
"label": i.label,
|
"label": i.label,
|
||||||
"type": i.type,
|
"type": i.type,
|
||||||
"number": i.number,
|
"number": i.number,
|
||||||
"value": "i.to_json()",
|
key: value
|
||||||
}
|
}
|
||||||
# append the fields to array
|
# append the fields to array
|
||||||
# use copy() to avoid overwriting
|
# use copy() to avoid overwriting
|
||||||
|
@ -63,6 +66,29 @@ def get_fields(s_id):
|
||||||
|
|
||||||
return field_set
|
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 Endpoints
|
||||||
@api_view(['POST'])
|
@api_view(['POST'])
|
||||||
|
|
BIN
back/db.sqlite3
BIN
back/db.sqlite3
Binary file not shown.
Loading…
Reference in a new issue