Move code generation to post_save signal