post_list = [
{
"post_key" : post.post_key,
"post_desc" : post.post_desc,
"updated_pub_date": post.updated_pub_date,
"first_img_url" :
post.postimage_set.all().first().img_url
}
for post in posts
]
result = {
user_name: {
"posts": post_list
}
}
post_list = [
{
"post_key" : post.post_key,
"post_desc" : post.post_desc,
"updated_pub_date": post.updated_pub_date,
"img_info" : [{
"url" : post_image.img_url,
"id" : post_image.pk
} for post_image
in post.postimage_set.all()]
}
for post in posts
]
result = {
user_name: {
"posts": post_list
}
}
리스트 안에 어떠한 자료 형태가 올 수 있다는 키를 캐치했다면, List Comprehension 으로 얼마든지 응용할 수 있는데.. 한 참 고민하다가 물어봤었다. 후..