我正在Project
使用Participants as embedded documents
. 以下是存储它的结构。
{ "_id" : ObjectId( "5277a15c2d6d1302a2a9bf88" ),
"code_certified" : true,
"description" : "This is gonna to be accepted.",
"owners" : [
"5277a1472d6d1302a2a9bf86" ],
"participants" : [
{ "id" : ObjectId( "5277a15c2d6d1302a2a9bf87" ),
"invitee" : { "email" : "pravin@gmail.com",
"name" : "P",
"id" : "5277a1472d6d1302a2a9bf86" },
"inviter" : { "email" : "pravin@gmail.com",
"name" : "P",
"id" : "5277a1472d6d1302a2a9bf86" },
"role" : "owner",
"date_invited" : Date( 1383523200000 ),
"status" : "accepted" },
{ "id" : ObjectId( "5277a17f2d6d1302a2a9bf8d" ),
"invitee" : { "id" : "5277a1282d6d1302a2a9bf85",
"name" : "Pravin Mhatre",
"email" : "pravinhmhatre@gmail.com" },
"inviter" : { "id" : "5277a1472d6d1302a2a9bf86",
"email" : "pravin@gmail.com",
"name" : "P M" },
"role" : "contributor",
"date_invited" : Date( 1383523200000 ),
"status" : "pending" } ],
"task_sequence" : 1,
"title" : "Accept" }
我想检索接受参与请求的项目列表(即参与者.status = "accepted")。
我正在尝试使用以下代码。但它返回所有项目。
ApiResponse(Project.objects.filter(participants__invitee__id=str(request.user.id), participants__status__iexact="accepted").all(), ProjectEncoder).respond()