Fix a bug in the create document function

Apparently you can no longer check if a non-nullable foreign key field
is null by just querying the field, i.e.

if not self.state

you have to do the following:

if not hasattr(self, 'state')