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
6719a48e
Commit
6719a48e
authored
Jul 27, 2015
by
Jacob Magnusson
Committed by
Paul Brown
Aug 23, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SQLA: Don’t require fields that have a default value
parent
f8e62a09
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
form.py
flask_admin/contrib/sqla/form.py
+5
-1
test_basic.py
flask_admin/tests/sqla/test_basic.py
+23
-1
No files found.
flask_admin/contrib/sqla/form.py
View file @
6719a48e
...
...
@@ -205,7 +205,11 @@ class AdminModelConverter(ModelConverterBase):
optional_types
=
getattr
(
self
.
view
,
'form_optional_types'
,
(
Boolean
,))
if
not
column
.
nullable
and
not
isinstance
(
column
.
type
,
optional_types
):
if
(
not
column
.
nullable
and
not
isinstance
(
column
.
type
,
optional_types
)
and
not
column
.
default
):
kwargs
[
'validators'
]
.
append
(
validators
.
InputRequired
())
# Apply label and description if it isn't inline form field
...
...
flask_admin/tests/sqla/test_basic.py
View file @
6719a48e
...
...
@@ -61,15 +61,22 @@ def create_models(db):
class
Model2
(
db
.
Model
):
def
__init__
(
self
,
string_field
=
None
,
int_field
=
None
,
bool_field
=
None
,
model1
=
None
,
float_field
=
None
):
model1
=
None
,
float_field
=
None
,
string_field_default
=
None
,
string_field_empty_default
=
None
):
self
.
string_field
=
string_field
self
.
int_field
=
int_field
self
.
bool_field
=
bool_field
self
.
model1
=
model1
self
.
float_field
=
float_field
self
.
string_field_default
=
string_field_default
self
.
string_field_empty_default
=
string_field_empty_default
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
string_field
=
db
.
Column
(
db
.
String
)
string_field_default
=
db
.
Column
(
db
.
Text
,
nullable
=
False
,
default
=
''
)
string_field_empty_default
=
db
.
Column
(
db
.
Text
,
nullable
=
False
,
default
=
''
)
int_field
=
db
.
Column
(
db
.
Integer
)
bool_field
=
db
.
Column
(
db
.
Boolean
)
enum_field
=
db
.
Column
(
db
.
Enum
(
'model2_v1'
,
'model2_v2'
),
nullable
=
True
)
...
...
@@ -1959,3 +1966,18 @@ def test_multipath_joins():
rv
=
client
.
get
(
'/admin/model2/'
)
eq_
(
rv
.
status_code
,
200
)
def
test_model_default
():
app
,
db
,
admin
=
setup
()
_
,
Model2
=
create_models
(
db
)
class
ModelView
(
CustomModelView
):
pass
view
=
ModelView
(
Model2
,
db
.
session
)
admin
.
add_view
(
view
)
client
=
app
.
test_client
()
rv
=
client
.
post
(
'/admin/model2/new/'
,
data
=
dict
())
assert_true
(
b
'This field is required'
not
in
rv
.
data
)
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