Allow to use ForeignKey field attributes at list_display in a simple way.

    Example:
        
        from misc.admin import foreign_field_func as ff

        class SongAdmin(admin.ModelAdmin):                                                                                                                        
            list_display = ['name', 'time', 'artist', 'album', ff('track__num', "Track number"), ff('album__total_tracks')]

def foreign_field_func(field_name, short_description=None, admin_order_field=None): 
    """
    Allow to use ForeignKey field attributes at list_display in a simple way.

    Example:
        
        from misc.admin import foreign_field_func as ff

        class SongAdmin(admin.ModelAdmin):                                                                                                                        
            list_display = ['name', 'time', 'artist', 'album', ff('track__num', "Track number"), ff('album__total_tracks')]
    """  
    def accessor(obj): 
        val = obj 
        for part in field_name.split('__'): 
            val = getattr(val, part) 
        return val 
    
    if short_description: 
        accessor.short_description = short_description 
    else: 
        accessor.__name__ = field_name 
    if admin_order_field: 
        accessor.admin_order_field = admin_order_field 
    else: 
        accessor.admin_order_field  = (field_name,) 
    
    return accessor