If you don't want to write a management command:
This is what you roughly have to do:
import os, import sys
# setup sys.path such, that it finds all required modules
# New setup the environment so, that django settings can be found
os.environ['DJANGO_SETTINGS_MODULE'] = 'your_project.settings'
# next lines recommended to be sure your own code can use logging
from django.conf import settings
# DO NOT REMOVE NEXT COMMAND (It forces django.setting's
# lazy evaluation to evaluate)
LOGGING = settings.LOGGING
import logging
# Now you can use logging with django setting's log setup
# Now You're free to use django
from your_project.your_app.models import MyModel
>
>
> Cheers
>
> Tom
>