2017-09-04 284 views

回答

2
from django.core.urlresolvers import reverse 
from django.contrib.contenttypes.models import ContentType 

    def get_order(self, obj): 
     try: 
      order_content_type = ContentType.objects.get_for_model(obj.order.__class__) 
      order_link = reverse("admin:%s_%s_change" % 
          (order_content_type.app_label, order_content_type.model), args=(obj.order.id,)) 
     return '<a href="%s">%s</a>' % (order_link, obj.order.tracking_code) 
     except AttributeError: 
      return '' 

    get_order.allow_tags = True 

把這個方法在您的管理類只用於通知

+0

:「爲支持ModelAdmin方法中的allow_tags屬性將被刪除。「](https://docs.djangoproject.com/en/dev/internals/deprecation/#deprecation-removed-in-2-0) –