- If you just want to use django ORM, please refer to Django ORM Standalone Template.
- If you want to use other python code to manipulate existing django database inside a project, using its pretty ORM, please do as following code:
# setup django environment using existing settings file
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")
django.setup()
# start of main code
from myapp.models import *
testobjs = mymodel.objects.all()
print(testobjs)