def save(self, force_insert=False, force_update=False, **kwargs):
<EOL>if self.parent == self:<EOL><INDENT>self.parent = None<EOL><DEDENT>id_ = self.id<EOL>if id_ and self.sort_order == <NUM_LIT:0>:<EOL><INDENT>self.sort_order = id_<EOL><DEDENT>super(TreeItemBase, self).save(force_insert, force_update, **kwargs)<EOL>if self.sort_order == <NUM_LIT:0>:<EOL><INDENT>self.sort_order = self.id<EOL>self.save()<EOL><DEDENT>
Ensure that item is not its own parent and set proper sort order.