标签:get direct dmi .com ^c false first dir hang
# 自定义多对多的显示 def display_customer(self,obj=None,is_field=False): if is_field: return "课程" else: ret = obj.course.all() temp=[] for course_obj in ret: s="<a style=‘border:1px solid #369;padding:3px 6px‘ href=‘/Xadmin/crm/customer/cancel/%s/%s‘>%s</a> "%(obj.pk,course_obj.pk,course_obj.name) temp.append(s) return mark_safe("".join(temp)) # 自定义url所对应的方法 def cansel_course(self,request,customer_id,course_id): print(customer_id,course_id) customer = self.model.objects.filter(pk=customer_id).first() customer.course.remove(course_id) return redirect(self.get_list_url()) # 自定义url def extra_url(self): temp=[] temp.append(url(r"^cancel/(\d+)/(\d+)",self.cansel_course)) return temp
list_display = [display_customer]
# 额外的url def extra_url(self): return [] def get_url2(self): app_name = self.model._meta.app_label model_name = self.model._meta.model_name temp=[] temp.append(url(r"^$", self.list_view,name="%s_%s_list"%(app_name,model_name))) temp.append(url(r"^add/$", self.add_view,name="%s_%s_add"%(app_name,model_name))) temp.append(url(r"^(\d+)/change/$", self.change_view,name="%s_%s_change"%(app_name,model_name))) temp.append(url(r"^(\d+)/delete/$", self.delete_view,name="%s_%s_delete"%(app_name,model_name))) temp.extend(self.extra_url()) return temp
点击课程标签,去除该课程:
标签:get direct dmi .com ^c false first dir hang
原文地址:https://www.cnblogs.com/fangsheng/p/9783245.html