def reverse_field_path(model, path):
 reversed_path = []
 parent = model
 pieces = path.split(LOOKUP_SEP)
 for piece in pieces:
  field = parent._meta.get_field(piece)
  direct = ((not field.auto_created) or field.concrete)
  if (len(reversed_path) == (len(pieces) - 1)):
   try:
    get_model_from_relation(field)
   except NotRelationField:
    break
  if direct:
   related_name = field.related_query_name()
   parent = field.rel.to
  else:
   related_name = field.field.name
   parent = field.model
  reversed_path.insert(0, related_name)
 return (parent, LOOKUP_SEP.join(reversed_path))

def reverse_field_path ( model , path ) : reversed_path = [ ] parent = model pieces = path . split ( LOOKUP_SEP ) for piece in pieces : field = parent . _meta . get_field ( piece ) direct = ( ( not field . auto_created ) or field . concrete ) if ( len ( reversed_path ) == ( len ( pieces ) - 1 ) ) : try : get_model_from_relation ( field ) except NotRelationField : break if direct : related_name = field . related_query_name ( ) parent = field . rel . to else : related_name = field . field . name parent = field . model reversed_path . insert ( 0 , related_name ) return ( parent , LOOKUP_SEP . join ( reversed_path ) )
create a reversed field path .