Running from a Cron Job (Scheduled task)
Simple way to run Django, having access to your models, from a cron job/scheduled task or command line.
Place a file into your app directory, alongside manage.py, called cron.py (for example).
from django.core.management import setup_environ
import settings
setup_environ(settings)
from blog.models import Blog
print Blog.objects.all()
Now, from the same directory, run;
python cron.py
Easy as that. Depending on your setup you may want to add more to your PYTHONPATH
or move this file to a different location.
import sys
sys.path.insert(0, '/home/domain.com/my_other_code') # top of the list
sys.path.append('/home/domain.dom/my_other_other_code') # bottom of the list