code: def find_all_models(models):
      
      for model in models:
          yield model
          # noinspection PyProtectedMember
          for parent in model._meta.parents.keys():
              for parent_model in find_all_models((parent,)):
                  yield parent_model
docs: Yield all models and their parents.