def gfk_expression(qs_model, gfk_field):
    # handle casting the GFK field if need be
    qn = connection.ops.quote_name
    
    pk_field_type = get_field_type(qs_model._meta.pk)
    gfk_field_type = get_field_type(gfk_field.model._meta.get_field(gfk_field.fk_field))
    if 'mysql' in connection.settings_dict['ENGINE'] and pk_field_type == 'integer':
        pk_field_type = 'unsigned'
    
    if pk_field_type != gfk_field_type:
        # cast the gfk to the pk type
        gfk_expr = "CAST(%s AS %s)" % (qn(gfk_field.fk_field), pk_field_type)
    else:
        gfk_expr = qn(gfk_field.fk_field) # the object_id field on the GFK
    
    return gfk_expr
dataset/ETHPy150Open coleifer/django-generic-aggregation/generic_aggregation/utils.py/gfk_expression/original