Guest User

Untitled

a guest
Dec 11th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. db_posts = Post.objects.values('id')\
  2.                            .filter(status='public')\
  3.                            .order_by('-date_create')
  4.                            
  5.     id_list = [post['id'] for post in db_posts]
  6.    
  7.     posts = []
  8.     for id in id_list:
  9.         post = Post.objects.get(id=id)
  10.         post_comments = Comment.objects.filter(post=id).count()
  11.         posts.append({
  12.             'id': post.id,
  13.             'title': post.title,
  14.             'intro_text': post.intro_text,
  15.             'main_text': post.main_text,
  16.             'cut': post.cut,
  17.             'date_create': post.date_create,
  18.             'date_update': post.date_update,
  19.             'status': post.status,
  20.             'tags': post.get_tags(),
  21.             'comments': post_comments,
  22.         })
Add Comment
Please, Sign In to add comment