mongoalchemy

Array Definition Modelling in MongoAlchemy

喜你入骨 提交于 2020-01-13 06:38:12
问题 I try to model my MongoAlchemy class in Flask. Here is my model: { "_id" : ObjectId("adfafdasfafag24t24t"), "name" : "sth." "surname" : "sth." "address" : [ { "city" : "Dublin" "country" : "Ireland" } ] } Here is my documents.py class: class Language_School(db.Document): name = db.StringField() surname = db.StringField() address = db.??? How can I define this like array model (address) in Flask? Edit: I have already tried to my models like before asking question. But I took error like

How to display an array of objects using python flask and mongoalchemy

做~自己de王妃 提交于 2019-12-24 08:12:11
问题 How to write an end point which will return a array of json objects for mongoalchemy I am trying to do as shown below: @authenticate_bp.route('/users',methods=['GET']) def user_list(): users = [x.serialize for x in TokenBasedAuth.query.all()] return jsonify({'usersList': users}) the schema is as shown below class TokenBasedAuth(db.Document): username = db.StringField() password = db.StringField() email = db.StringField() firstName = db.StringField() lastName = db.StringField() def serialize(g

MongoAlchemy query embedded documents

我的梦境 提交于 2019-12-22 01:32:05
问题 I want to know how to use MongoAlchemy about embeded docment operation. But I havn't find any documents about these. Can anyone give me some helps? Here is demo code: #!/usr/bin/python # -*- coding: utf-8 -*- from flask import Flask from flaskext.mongoalchemy import MongoAlchemy app = Flask(__name__) app.config['DEBUG'] = True app.config['MONGOALCHEMY_DATABASE'] = 'book' db = MongoAlchemy(app) class Comment(db.Document): user_id = db.StringField(db_field='uid') posted = db.StringField(db

Array Definition Modelling in MongoAlchemy

前提是你 提交于 2019-12-04 18:53:58
I try to model my MongoAlchemy class in Flask. Here is my model: { "_id" : ObjectId("adfafdasfafag24t24t"), "name" : "sth." "surname" : "sth." "address" : [ { "city" : "Dublin" "country" : "Ireland" } ] } Here is my documents.py class: class Language_School(db.Document): name = db.StringField() surname = db.StringField() address = db.??? How can I define this like array model (address) in Flask? Edit: I have already tried to my models like before asking question. But I took error like "AttributeError AttributeError: 'list' object has no attribute 'items'". class Address(db.Document): city = db