python_wiki:django_api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

python_wiki:django_api [2018/08/04 00:05]
billdozor [Load Objects]
python_wiki:django_api [2019/05/25 23:50]
Line 1: Line 1:
-====== Django API ====== 
- 
-**General Information** 
- 
-Interacting with the Django Python API.  
- 
-**Checklist** 
-  * [[django_install|Django Installed]] 
-  * [[django_configuration|Django Configured]] 
- 
----- 
- 
-====== Imports ====== 
- 
-Imports and settings to add to your Python script in order to use your Django App's built in API. 
- 
-\\ 
-Import and Settings 
-<code python> 
-#!/usr/bin/python 
- 
-# Import Django WSGI App Loading capabilities 
-from django.core.wsgi import get_wsgi_application 
- 
-##- Configure Django Settings to point to your App -## 
-# sys.path = where manage.py is 
-sys.path.append('/home/django/myprojecthere') 
- 
-# Settings Module = projectname.settings 
-os.environ["DJANGO_SETTINGS_MODULE"] = 'myprojecthere.settings' 
-application = get_wsgi_application() 
- 
-# Import Django App Model (from 'myapphere' app) 
-from myapphere.models import AssetEntry 
-</code> 
- 
----- 
- 
-====== Using Your Apps API ====== 
- 
-Different ways to get your app data. 
- 
-===== Load Objects ==== 
- 
-Objects can now be retrieved just like in views.py. 
-<code python> 
-# Load all assets (just like in views.py) 
-asset_list = AssetEntry.objects.order_by('asset_type', 'asset_env', 'asset_name') 
- 
-# Print all names 
-for node in asset_list: 
-  print(node.asset_name) 
-</code> 
- 
-===== Save Objects ==== 
- 
-FIXME - To Do 
- 
----- 
  
  • python_wiki/django_api.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)