im使用flask_mongoengine
这里是集合模式:
class collegeModel(DATABASE.Document):
name = DATABASE.StringField(required=True)
city = DATABASE.StringField(default = "NA")
state = DATABASE.StringField(default="NA")
country = DATABASE.StringField(default="NA")
university = DATABASE.ReferenceField(UniversityModel,required=True)
timestamp = DATABASE.DateTimeField(default = datetime.datetime.now())
这里是宇宙模式:
class UniversityModel(DATABASE.Document):
name = DATABASE.StringField(required = True)
city = DATABASE.StringField()
state = DATABASE.StringField()
country = DATABASE.StringField()
timestamp = DATABASE.DateTimeField(default = datetime.datetime.now())
我想做的是获取特定大学下的所有学院*
colModel = collegeModel.objects.filter(university=universityid)
data = json.loads(colModel.to_json())
return {
'status': 'success',
'msg': f'SUCCESFULLY FETCHED THE COLLEGES UNDER UNIVERSITY: {UniversityModel.objects.get(id=universityid).name}',
'data': data
}
collegeModel.objects.filter(university=universityid(