Fixes #2826: only run set_code() on submit if the config template editor is already in diff mode

(cherry picked from commit ceabd2b37d1924a45ee20de100d0e5cb8f39845d)
fixes #2801 - remove LOWER() in default_scope of models that could cause PG error

(cherry picked from commit 60e2072a7751819b1d870681294e3feff3de3cbf)