code: def get_by_instance(self, instance):
          
          # we iterate throught registered preference models in order to get the instance class
          # and check if instance is and instance of this class
          for model, registry in self.items():
              try:
                  instance_class = model._meta.get_field('instance').remote_field.model
                  if isinstance(instance, instance_class):
                      return registry
  
              except FieldDoesNotExist:  # global preferences
                  pass
          return None
docs: Return a preference registry using a model instance