Fix for #320 TypeError: Model instances without primary key value are unhashable