Thursday, October 27, 2016

Re: Running django on demand via my PyQt4 Standalone app

I have a Django project that is used to view complex data for use by Systems Engineers who are analyzing requirements traceability. Django works great for the viewing of data in lots of differing views. The templating system is awesome for that.

However the data that is being viewed is coming from ugly Excel spreadsheets. So I have several scripts that pull the relevant data from these spreadsheets and use it to create the database for use by Django.

In order to access the models in Django, each of these scripts starts with:

import os
import sys

lib_path = os.path.abspath("[path to Django project]")
sys.path.append(lib_path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
import django
django.setup()

from [app].models import L1_requirement, L2_requirement, ...

I can then use the Django methods on my_model.objects to get, filter, save my various requirement models.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8e499ff7-985b-431b-8e98-776354ddf3fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment