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
155f508e
Commit
155f508e
authored
Sep 18, 2016
by
Serge S. Koval
Committed by
GitHub
Sep 18, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1351 from vToMy/bugfix/m2m_example
Fixes #1339 and adds python 3 support to the example
parents
2797c94c
93ab083e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
app.py
examples/sqla/app.py
+13
-7
No files found.
examples/sqla/app.py
View file @
155f508e
...
...
@@ -2,6 +2,7 @@ import os
import
os.path
as
op
from
flask
import
Flask
from
flask_sqlalchemy
import
SQLAlchemy
from
future.utils
import
python_2_unicode_compatible
from
wtforms
import
validators
...
...
@@ -20,10 +21,12 @@ app.config['SECRET_KEY'] = '123456790'
app
.
config
[
'DATABASE_FILE'
]
=
'sample_db.sqlite'
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///'
+
app
.
config
[
'DATABASE_FILE'
]
app
.
config
[
'SQLALCHEMY_ECHO'
]
=
True
db
=
SQLAlchemy
(
app
)
session_options
=
dict
(
autoflush
=
False
)
db
=
SQLAlchemy
(
app
,
session_options
=
session_options
)
# Create models
@
python_2_unicode_compatible
class
User
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
first_name
=
db
.
Column
(
db
.
String
(
100
))
...
...
@@ -31,8 +34,7 @@ class User(db.Model):
username
=
db
.
Column
(
db
.
String
(
80
),
unique
=
True
)
email
=
db
.
Column
(
db
.
String
(
120
),
unique
=
True
)
# Required for administrative interface. For python 3 please use __str__ instead.
def
__unicode__
(
self
):
def
__str__
(
self
):
return
self
.
username
...
...
@@ -43,6 +45,7 @@ post_tags_table = db.Table('post_tags', db.Model.metadata,
)
@
python_2_unicode_compatible
class
Post
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
title
=
db
.
Column
(
db
.
String
(
120
))
...
...
@@ -54,18 +57,20 @@ class Post(db.Model):
tags
=
db
.
relationship
(
'Tag'
,
secondary
=
post_tags_table
)
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
self
.
title
@
python_2_unicode_compatible
class
Tag
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
Unicode
(
64
))
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
self
.
name
@
python_2_unicode_compatible
class
UserInfo
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
...
...
@@ -75,17 +80,18 @@ class UserInfo(db.Model):
user_id
=
db
.
Column
(
db
.
Integer
(),
db
.
ForeignKey
(
User
.
id
))
user
=
db
.
relationship
(
User
,
backref
=
'info'
)
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
'
%
s -
%
s'
%
(
self
.
key
,
self
.
value
)
@
python_2_unicode_compatible
class
Tree
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
String
(
64
))
parent_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'tree.id'
))
parent
=
db
.
relationship
(
'Tree'
,
remote_side
=
[
id
],
backref
=
'children'
)
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
self
.
name
...
...
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