How to query Django model from views.py file?

Viewed 7066

I have a model named Search in my models.py file. I have made migrations and everything is working totally fine except one problem. In my views.py file I have created one variable called var1 which queries "search_query" field into the database, but unfortunately, it couldn't assign that variable. Please help me how to access my model to work this line,

var1 = Search.objects.latest('search_query')

Here is my models.py file,

from django.db import models

class Search(models.Model):
    search_query = models.CharField(max_length=64)

views.py file,

from django.shortcuts import render, redirect
import requests
from git_profile.forms import SearchForm
from git_profile.models import Search

def index(request):
    var1 = Search.objects.latest('search_query')

EDIT:

I want to replace 'var1' with this replacement python user_profile = requests.get('https://api.github.com/users/{0}'.format(str(v‌​‌​ar1))) content = dict() content['user'] = user_profile.json() but var1 can not be replaced by replacement field and API gives me weird error

3 Answers
Related