0

I have a simple web2py app that implements a RESTful API. In my model, I have something like:

db.define_table('vehicles',
                Field('flightId', type='string', default='00000', length=128, 
                .
                .
                .
                Field('route', 'reference path'),
                )

db.define_table('path',
                Field('coordinates', type='list:integer', requires=IS_NOT_EMPTY()))

I want my vehicle to be able to reference a path, which is then managed by another database entry. This path, of course, will be given by coordinate pairs in latitude/longitude so actually a list of tuples would be best. Is there a more sensible way to do this? How would I post a list of ints? Could I just use requests to do this?

The client needs to be able to query the vehicle a lot, but I would like not to send the full path each time this happens as there are many points along the path. I'm totally out of my element with web stuff, so I appreciate any help, tips or resources anyone can provide in this regard.

RYS
  • 442
  • 6
  • 22

1 Answers1

1

I don't see how you would store a sequence of latitude/longitude pairs in a list:integer field. Instead, you might consider the following options:

  1. Make db.path.coordinates a json field, and submit the coordinates as a JSON object. When retrieving records from the table, the web2py DAL will automatically convert the JSON to a Python object for manipulation with Python.
  2. Use a string or text field and create your own custom serialization of the data into a string format, parsing the data yourself when doing inserts and selects.
  3. Implement option #2 using either filter_in/filter_out or a custom field type.
Anthony
  • 25,466
  • 3
  • 28
  • 57
  • Right, when I made a form to fill it out I realized `list:integer` was not what I expected it was. Option 1 worked well for me, though it was not as straightforward as I thought it would be to modify my model. – RYS Oct 01 '15 at 08:19