Skip to content

Commit

Permalink
Fix boolean field constraint name
Browse files Browse the repository at this point in the history
  • Loading branch information
shosca committed Nov 24, 2018
1 parent 5e0adea commit f259c0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions django_sorcery/db/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"SmallIntegerField",
"TextField",
"TimeField",
"TimestampField",
"URLField",
]

Expand Down Expand Up @@ -115,6 +116,11 @@ class BooleanField(Field):
type_class = sa.Boolean
form_class = djangofields.BooleanField

def get_type_kwargs(self, type_class, kwargs):
type_kwargs = super(BooleanField, self).get_type_kwargs(type_class, kwargs)
type_kwargs["name"] = kwargs.pop("constraint_name", None)
return type_kwargs

def get_column_kwargs(self, kwargs):
column_kwargs = super(BooleanField, self).get_column_kwargs(kwargs)
column_kwargs["nullable"] = False
Expand Down
6 changes: 6 additions & 0 deletions tests/db/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def test_boolean_field(self):
form_field = meta.column_info(column).formfield()
self.assertIsInstance(form_field, djangofields.BooleanField)

column = fields.BooleanField(constraint_name="test")
self.assertEqual(column.type.name, "test")

def test_char_field(self):
column = fields.CharField()
self.assertIsInstance(column.type, sa.String)
Expand Down Expand Up @@ -164,6 +167,9 @@ def test_nullboolean_field(self):
self.assertIsInstance(column.type, sa.Boolean)
self.assertTrue(column.nullable)

column = fields.NullBooleanField(constraint_name="test")
self.assertEqual(column.type.name, "test")

form_field = meta.column_info(column).formfield()
self.assertIsInstance(form_field, djangofields.NullBooleanField)

Expand Down

0 comments on commit f259c0f

Please sign in to comment.