File tree 4 files changed +82
-0
lines changed
4 files changed +82
-0
lines changed Original file line number Diff line number Diff line change
1
+ Installation
2
+ ============
3
+
4
+ To install pymongo2django::
5
+
6
+ copy pymongo2django to the django project directory storing the manage.py file
7
+
8
+ Software Requirement
9
+ ====================
10
+
11
+ The follow software requirement to install pymongo2django app::
12
+
13
+ * Python 2.7.x
14
+ * Pymongo Driver (latest version preferred)
15
+ * MongoDB Server (http://www.mongodb.org) only if database is installed
16
+ locally on your machine otherwise you can access database from the
17
+ cloud through MongoDB servers online (http://www.mongolab.com/)
18
+
19
+ Usage
20
+ =====
21
+ To use pymongo2django with your Django project, just add these lines to your settings.py file::
22
+
23
+ Add to the 'INSTALLED_APPS' section the pymongo2django app and append it to the end of this section ::
24
+
25
+ INSTALLED_APPS = (
26
+ ...
27
+ 'pymongo2django',
28
+ )
29
+
30
+ Update the pymongo2django/settings.py file found inside the pymongo2django directory.
31
+ Update the variables in this file to use database.
32
+
33
+ For instance, to create a DB instance::
34
+
35
+ >>> from pymongo2django import get_DBInstance
36
+ >>> db = get_DBInstance()
37
+
38
+ To find an item in a collection::
39
+
40
+ >>> from pymongo2django import get_DBInstance
41
+ >>> db = get_DBInstance()
42
+ >>> col = db.tester
43
+ >>> for row in col.find():
44
+ >>> print row
Original file line number Diff line number Diff line change
1
+ import settings
2
+ from backend import get_DBInstance
Original file line number Diff line number Diff line change
1
+ import settings
2
+ from pymongo import MongoClient
3
+ from pymongo .database import DBRef
4
+
5
+
6
+ def get_DBInstance ():
7
+
8
+ connStr = userStr = db = None
9
+
10
+ if settings .user and settings .password :
11
+ userStr = settings .user + ":" + settings .password + "@"
12
+
13
+ if userStr :
14
+ connStr = 'mongodb://' + userStr + settings .host
15
+ else :
16
+ connStr = 'mongodb://' + settings .host
17
+
18
+ if settings .port :
19
+ connStr += ':' + str (settings .port )
20
+
21
+ if settings .name :
22
+ connStr += '/' + settings .name
23
+ conn = MongoClient (connStr )
24
+ db = conn [settings .name ]
25
+
26
+ return db
27
+
Original file line number Diff line number Diff line change
1
+ #Stores settings to mongodb server
2
+
3
+ host = '' #localhost or machine name
4
+ port = None #port number or leave empty and default to port 27017
5
+ name = '' #database name
6
+ user = '' #user name to database
7
+ password = '' #user password to database
8
+
9
+
You can’t perform that action at this time.
0 commit comments