Update some database-related logic to support Django 1.6 and higher.
Review Request #8686 — Created Jan. 31, 2017 and submitted
Different versions of Django have different accessors and classes for
parts of the ORM. This change adds compatibility for these accessors and
classes in a way that's compatible with Django 1.6 and higher.
We also have to re-implement cloning of
Q()objects, since this was
removed in a recent version of Django.
Unit tests pass for Django 1.6, 1.7, 1.8, 1.9, and 1.10.