I\'m using this below in views.py to get app
from django.db import connection
def test(request):
cursor = connection.cursor()
sql = \"
You need to use Django's built in QuerySet API
. More information on it can be seen here. Once you create a QuerySet
you can then use pandas read_sql_query
method to construct the data frame. The simplest way to construct a QuerySet
is simply query the entire database which can be done like so:
db_query = YourModel.objects.all()
You can use filters which are passed in as args when querying the database to create different QuerySet
objects depending on what your needs are.
Then using pandas you could do something like:
d_frame = pandas.read_sql_query(db_query, other_args...)