Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9b5d0e1

Browse files
committed
add association query one to many support
1 parentd746fb2 commit9b5d0e1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

‎demo/apps/apijson_demo/views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ def index():
122122
"email$":"%local%"
123123
}
124124
}
125+
}''',
126+
},
127+
{
128+
"label":"Array query: association query one to many",
129+
"value":'''{
130+
"moment": {},
131+
"[]": {
132+
"comment": {
133+
"moment_id@": "moment/id"
134+
}
135+
}
125136
}''',
126137
},
127138
{

‎uliweb_apijson/apijson/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def get(self):
5555
rsp=self._get_one(key)
5656
ifrsp:returnrsp
5757
self._apply_vars()
58+
exceptUliwebErrorase:
59+
returnjson({"code":400,"msg":str(e)})
5860
exceptExceptionase:
5961
err="exception when handling 'apijson get': %s"%(e)
6062
log.error(err)
@@ -230,6 +232,20 @@ def _get_array(self,key):
230232

231233
model_expr=model_param.get("@expr")
232234

235+
#update reference
236+
ref_fields= []
237+
refs= {}
238+
forninmodel_param:
239+
ifn[-1]=="@":
240+
ref_fields.append(n)
241+
col_name=n[:-1]
242+
path=model_param[n]
243+
refs[col_name]=self._ref_get(path)
244+
ifref_fields:
245+
foriinref_fields:
246+
delmodel_param[i]
247+
model_param.update(refs)
248+
233249
ifmodel_expr:
234250
c=self._expr(model,model_param,model_expr)
235251
q=q.filter(c)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp