(cls, name)
Dynamically creates a new method for each URLField and ForeignKey/OneToOneField field that will return the
            object name with a link to either the webpage (if URLField) or admin change page
            (if ForeignKey/OneToOneField).
Dynamically creates a new method for each URLField and ForeignKey/OneToOneField field that will return the
            object name with a link to either the webpage (if URLField) or admin change page
            (if ForeignKey/OneToOneField).
Dynamically creates a new method for each URLField and ForeignKey / OneToOneField field that will return the object name with a link to either the webpage ( if URLField ) or admin change page ( if ForeignKey / OneToOneField ) .
def __getattr__(cls, name):
        """
            Dynamically creates a new method for each URLField and ForeignKey/OneToOneField field that will return the
            object name with a link to either the webpage (if URLField) or admin change page
            (if ForeignKey/OneToOneField).
        """
        def url_link(instance, field):
            target = getattr(instance, field)
            if not target:
                return ""
            return '<a href="%s">%s</a>' % (target, target)

        def foreign_key_link(instance, field):
            target = getattr(instance, field)
            if not target:
                return "None"
            return u'<a href="../../%s/%s/%d">%s</a>' % (
                target._meta.app_label, target._meta.model_name, target.id, smart_text(target))

        if name[:9] == 'url_link_':
            method = partial(url_link, field=name[9:])
            method.__name__ = name[9:]
            method.allow_tags = True
            method.admin_order_field = name[9:]
            setattr(cls, name, method)
            return getattr(cls, name)

        if name[:8] == 'fk_link_':
            method = partial(foreign_key_link, field=name[8:])
            method.__name__ = name[8:]
            method.allow_tags = True
            setattr(cls, name, method)
            return getattr(cls, name)
        raise AttributeError
def __getattr__ ( cls , name ) : def url_link ( instance , field ) : target = getattr ( instance , field ) if not target : return "" return '<a href="%s">%s</a>' % ( target , target ) def foreign_key_link ( instance , field ) : target = getattr ( instance , field ) if not target : return "None" return u'<a href="../../%s/%s/%d">%s</a>' % ( target . _meta . app_label , target . _meta . model_name , target . id , smart_text ( target ) ) if name [ : 9 ] == 'url_link_' : method = partial ( url_link , field = name [ 9 : ] ) method . __name__ = name [ 9 : ] method . allow_tags = True method . admin_order_field = name [ 9 : ] setattr ( cls , name , method ) return getattr ( cls , name ) if name [ : 8 ] == 'fk_link_' : method = partial ( foreign_key_link , field = name [ 8 : ] ) method . __name__ = name [ 8 : ] method . allow_tags = True setattr ( cls , name , method ) return getattr ( cls , name ) raise AttributeError