Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

rest api django return value if exists in another table

class PostList(generics.ListAPIView):
    ...
    def get_queryset(self):
        Post.objects.all().extra(select={
        'current_user_replies_count': 'SELECT COUNT(*) FROM <reply table> WHERE' +
        'post_id=posts_post.id AND owner_id = %s'
                                  },select_params=(request.user.id,))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #rest #api #django #return #exists #table
ADD COMMENT
Topic
Name
9+2 =