@@ -243,7 +243,9 @@ class Dog(db.Document):
243243 class DogOwner (db .Document ):
244244 dog = db .ReferenceField (Dog )
245245
246- DogOwnerForm = model_form (DogOwner )
246+ DogOwnerForm = model_form (DogOwner , field_args = {
247+ 'dog' : { 'allow_blank' : True }
248+ })
247249
248250 dog = Dog (name = "fido" )
249251 dog .save ()
@@ -254,6 +256,15 @@ class DogOwner(db.Document):
254256 self .assertEqual (wtforms .widgets .Select , type (form .dog .widget ))
255257 self .assertFalse (form .dog .widget .multiple )
256258
259+ # Validate the options - should contain a dog (selected) and a
260+ # blank option there should be an extra blank option.
261+ choices = list (form .dog )
262+ self .assertEqual (len (choices ), 2 )
263+ self .assertFalse (choices [0 ].checked )
264+ self .assertEqual (choices [0 ].data , '__None' )
265+ self .assertTrue (choices [1 ].checked )
266+ self .assertEqual (choices [1 ].data , dog .pk )
267+
257268 # Validate selecting one item
258269 form = DogOwnerForm (MultiDict ({
259270 'dog' : dog .id ,
@@ -289,7 +300,6 @@ class DogOwner(db.Document):
289300
290301 self .assertEqual (wtforms .widgets .Select , type (form .dogs .widget ))
291302 self .assertTrue (form .dogs .widget .multiple )
292- self .assertTrue (form .dogs .widget )
293303
294304 # Validate the options - both dogs should be selected and
295305 # there should be an extra blank option.
0 commit comments