I\'m new to Django and want to use its ORM in my scripts without running whole Django thing. I\'m scratching my head how to configure it. Searches on StackOverflow didn\'t h
Here's an updated version, fix was including django.setup() line and some additional settings and includes:
manage.py
import os
import sys
import django
from django.conf import settings
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
INSTALLED_APPS = [
'orm',
]
DATABASES = {
'default': {
'ENGINE' : 'django.db.backends.mysql',
'NAME' : 'playground',
'USER' : 'admin',
'PASSWORD' : 'pasw',
'HOST' : 'localhost',
}
}
settings.configure(
INSTALLED_APPS = INSTALLED_APPS,
DATABASES = DATABASES,
)
django.setup()
if __name__ == "__main__":
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
And app.py:
import manage
from orm.models import Label
if __name__ == '__main__':
Label.objects.create(name='test')
print(Label.objects.get(name='test'))
Hope someone will find it useful.