How to test in Django if the database retrieval logic sits in the view

I am using Django and two databases namely NDB and SQlite for different purposes. I have gone through testing topics in django, they tell to create database in the test and call the view/function for that object.

My scenario is different. I have database logic sitting in my function/view to test. So I cannot create a test database and test test function.

My view

class NewsFeedViewSet(viewsets.ViewSet):
lookup_field = 'username'

def retrieve(self, request , username=None):
    posts_list = []
    post_dict = {}
    ancestor_key = ndb.Key(Follow, username)
    user_followers = Follow.query_followers(ancestor_key)
    for followers in user_followers:

    posts = Post.query(Post.owner.IN(user_and_followers_list), < time_stamp).fetch(100)
    for p in posts:
        post_dict = p.to_dict()

    users = User.objects.filter(username__in=user_and_followers_list)
    for post in posts_list:
        user = users.get(username=post['owner'])
        serializer = UserSerializer(user)
        post['user'] =
    posts_list = sorted(posts_list, key=lambda k: k['date'], reverse=True)
    global time_stamp
    if len(posts_list) > 0:
        time_stamp = posts_list[len(posts_list)-1]['date']
    return Response(posts_list)   

Is there anyway to hit my production database and have my server running while I test? Or any different and efficient approach I could go with?