nodes: 0, module; 1, function_definition; 2, function_name:prepare_sort_key; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, if_statement; 8, comment:# we reverse sort by ( len(mro), source code order ) so subclasses match first; 9, comment:# on same types, last declared method sorts first; 10, expression_statement; 11, string; 12, call; 13, block; 14, assignment; 15, string_content:Triggered by view_function._sort_converters when our sort key should be created.
          This can't be called in the constructor because Django models might not be ready yet.; 16, identifier:isinstance; 17, argument_list; 18, try_statement; 19, try_statement; 20, attribute; 21, tuple; 22, attribute; 23, identifier:str; 24, block; 25, except_clause; 26, block; 27, except_clause; 28, identifier:self; 29, identifier:sort_key; 30, binary_operator:-1 * len(inspect.getmro(self.convert_type)); 31, binary_operator:-1 * self.source_order; 32, identifier:self; 33, identifier:convert_type; 34, expression_statement; 35, identifier:ValueError; 36, block; 37, expression_statement; 38, as_pattern; 39, block; 40, unary_operator; 41, call; 42, unary_operator; 43, attribute; 44, assignment; 45, raise_statement; 46, assignment; 47, identifier:LookupError; 48, as_pattern_target; 49, raise_statement; 50, integer:1; 51, identifier:len; 52, argument_list; 53, integer:1; 54, identifier:self; 55, identifier:source_order; 56, pattern_list; 57, call; 58, call; 59, attribute; 60, call; 61, identifier:e; 62, call; 63, call; 64, identifier:app_name; 65, identifier:model_name; 66, attribute; 67, argument_list; 68, identifier:ImproperlyConfigured; 69, argument_list; 70, identifier:self; 71, identifier:convert_type; 72, attribute; 73, argument_list; 74, identifier:ImproperlyConfigured; 75, argument_list; 76, attribute; 77, argument_list; 78, attribute; 79, identifier:split; 80, string; 81, call; 82, identifier:apps; 83, identifier:get_model; 84, identifier:app_name; 85, identifier:model_name; 86, call; 87, identifier:inspect; 88, identifier:getmro; 89, attribute; 90, identifier:self; 91, identifier:convert_type; 92, string_content:.; 93, attribute; 94, argument_list; 95, attribute; 96, argument_list; 97, identifier:self; 98, identifier:convert_type; 99, string:'"{}" is not a valid converter type. String-based converter types must be specified in "app.Model" format.'; 100, identifier:format; 101, attribute; 102, string:'"{}" is not a valid model name. {}'; 103, identifier:format; 104, attribute; 105, identifier:e; 106, identifier:self; 107, identifier:convert_type; 108, identifier:self; 109, identifier:convert_type
code: def prepare_sort_key(self):
          '''
          Triggered by view_function._sort_converters when our sort key should be created.
          This can't be called in the constructor because Django models might not be ready yet.
          '''
          if isinstance(self.convert_type, str):
              try:
                  app_name, model_name = self.convert_type.split('.')
              except ValueError:
                  raise ImproperlyConfigured('"{}" is not a valid converter type. String-based converter types must be specified in "app.Model" format.'.format(self.convert_type))
              try:
                  self.convert_type = apps.get_model(app_name, model_name)
              except LookupError as e:
                  raise ImproperlyConfigured('"{}" is not a valid model name. {}'.format(self.convert_type, e))
  
          # we reverse sort by ( len(mro), source code order ) so subclasses match first
          # on same types, last declared method sorts first
          self.sort_key = ( -1 * len(inspect.getmro(self.convert_type)), -1 * self.source_order )