S
S
Shooa2014-12-04 09:27:06
Flask
Shooa, 2014-12-04 09:27:06

Flask restless nesting?

class Item(db.Model):
    id = Column(Integer, primary_key=True)
    title = Column(Text, unique=False)
    field = relationship("Field")


class Field(db.Model):
    id = Column(Integer, primary_key=True)
    name = Column(Text, unique=False)
    measurement = relationship("Measurement")
    item_id = Column(Integer, ForeignKey('item.id'))


class Measurement(db.Model):
    id = Column(Integer, primary_key=True)
    name = Column(Text, unique=False)
    field_id = Column(Integer, ForeignKey('field.id'))

api_manager = APIManager(app, flask_sqlalchemy_db=db)
api_manager.create_api(Item, methods=['GET', 'POST', 'DELETE', 'PUT'])

Answer:
{
  "num_results": 2, 
  "objects": [
    {
      "field": [
        {
          "id": 1, 
          "item_id": 1, 
          "name": "fild1"
        }, 
        {
          "id": 2, 
          "field_id": 1, 
          "name": "fild2"
        }
      ], 
      "id": 1, 
      "title": "mes#1"
    }, 
    {
      "field": [
        {
          "id": 3, 
          "item_id": 2, 
          "name": "fildd1"
        }, 
        {
          "id": 4, 
          "lab_id": 2, 
          "name": "fildd2"
        }
      ], 
      "id": 2, 
      "title": "mes#2"
    }
  ], 
  "page": 1, 
  "total_pages": 1
}

In Item'e Field, however there is no Measurement in Field. Am I doing something fundamentally wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question