Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
590bebcf
Commit
590bebcf
authored
Mar 13, 2017
by
Bruno Rocha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small fixes and right url in requirements
parent
9a8d73ad
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
20 deletions
+23
-20
app.py
examples/tinymongo/app.py
+22
-19
requirements.txt
examples/tinymongo/requirements.txt
+1
-1
No files found.
examples/tinymongo/app.py
View file @
590bebcf
from
tinymongo
import
TinyMongoClient
from
bson.objectid
import
ObjectId
"""
Example of Flask-Admin using TinyDB with TinyMongo
refer to README.txt for instructions
from
flask
import
Flask
Author: Bruno Rocha <@rochacbruno>
Based in PyMongo Example and TinyMongo
"""
import
flask_admin
as
admin
from
wtforms
import
form
,
fields
from
flask_admin.form
import
Select2Widget
from
flask
import
Flask
from
flask_admin.contrib.pymongo
import
ModelView
,
filters
from
flask_admin.model.fields
import
InlineFormField
,
InlineFieldList
from
flask_admin.form
import
Select2Widget
from
flask_admin.model.fields
import
InlineFieldList
,
InlineFormField
from
wtforms
import
fields
,
form
from
tinymongo
import
TinyMongoClient
# Create application
app
=
Flask
(
__name__
)
...
...
@@ -16,8 +20,11 @@ app = Flask(__name__)
# Create dummy secrey key so we can use sessions
app
.
config
[
'SECRET_KEY'
]
=
'123456790'
# Create models
conn
=
TinyMongoClient
(
'/tmp/flask_admin_test'
)
# Create models in a JSON file localted at
DATAFOLDER
=
'/tmp/flask_admin_test'
conn
=
TinyMongoClient
(
DATAFOLDER
)
db
=
conn
.
test
# create some users for testing
...
...
@@ -73,22 +80,18 @@ class TweetView(ModelView):
filters
.
FilterNotLike
(
'name'
,
'Name'
),
filters
.
BooleanEqualFilter
(
'testie'
,
'Testie'
))
column_searchable_list
=
(
'name'
,
'text'
)
#
column_searchable_list = ('name', 'text')
form
=
TweetForm
def
get_list
(
self
,
*
args
,
**
kwargs
):
count
,
data
=
super
(
TweetView
,
self
)
.
get_list
(
*
args
,
**
kwargs
)
# Grab user names
query
=
{
'_id'
:
{
'$in'
:
[
x
[
'user_id'
]
for
x
in
data
]}}
users
=
db
.
user
.
find
(
query
,
fields
=
(
'name'
,))
# Contribute user names to the models
users_map
=
dict
((
x
[
'_id'
],
x
[
'name'
])
for
x
in
users
)
# Contribute user_name to the models
for
item
in
data
:
item
[
'user_name'
]
=
users_map
.
get
(
item
[
'user_id'
])
item
[
'user_name'
]
=
db
.
user
.
find_one
(
{
'_id'
:
item
[
'user_id'
]}
)[
'name'
]
return
count
,
data
...
...
examples/tinymongo/requirements.txt
View file @
590bebcf
Flask
Flask-Admin
git+https://github.com/
rochacbruno
/tinymongo.git#egg=tinymongo
git+https://github.com/
schapman1974
/tinymongo.git#egg=tinymongo
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment