(model_class)
return relation_fields
get related fields (m2m, fk, and reverse fk)
get related fields (m2m, fk, and reverse fk)
get related fields ( m2m fk and reverse fk )
def get_relation_fields_from_model(model_class):
    """ get related fields (m2m, fk, and reverse fk) """
    relation_fields = []
    all_fields_names = get_all_field_names(model_class)
    for field_name in all_fields_names:
        field = copy.deepcopy(model_class._meta.get_field(field_name))
        direct = field.concrete
        m2m = field.many_to_many
        # get_all_field_names will return the same field
        # both with and without _id. ignore the duplicate.
        if field_name[-3:] == '_id' and field_name[:-3] in all_fields_names:
            continue
        if m2m or not direct or field.is_relation:
            field.field_name = field_name
            relation_fields += [field]
    return relation_fields
def get_relation_fields_from_model ( model_class ) : relation_fields = [ ] all_fields_names = get_all_field_names ( model_class ) for field_name in all_fields_names : field = copy . deepcopy ( model_class . _meta . get_field ( field_name ) ) direct = field . concrete m2m = field . many_to_many # get_all_field_names will return the same field # both with and without _id. ignore the duplicate. if field_name [ - 3 : ] == '_id' and field_name [ : - 3 ] in all_fields_names : continue if m2m or not direct or field . is_relation : field . field_name = field_name relation_fields += [ field ] return relation_fields