Stark component Extension URL
This feature is used in many places.
The requirement for an example here is that in the Customer View page, clicking on a course name in the consulting course will unbind the course from the corresponding classmate (no longer shown)
To implement this requirement, you need to add a new URL in which we can get the course ID that we want to unbind and the primary key for the record in the table.
The method is the same as filter, Pop, and so on, it is set in the table corresponding to its own configuration class, so that the table has this independent URL
In stark.py, we set a separate configuration class for customer This table, Extra_url returns a URL with the corresponding view function as Self.cancel_course:
class Customerconfig (Modelstark): #处理课程的显示样式和每个课程对应的url, the URL contains the course ID to be unbound and the primary key ID of this record in the table Def display_course (self, O Bj=none, Is_header=false): If Is_header:return "consulting course" TEMP = [] for course_obj in Obj.cou Rse.all (): s = "<a href= '/stark/crm/customer/cancel_course/%s/%s ' style= ' border:1px solid #369;p adding:3px 6 px ' ><span>%s</span></a>  '% (obj.pk, course_obj.pk, Course_obj.name) temp.append (s Return Mark_safe ("". Join (temp)) #视图函数, implements the Delete function after click Def cancel_course (self, request, customer_id, course_id): obj = Customer.objects.filter (pk=customer_id). First () Obj.course.remove (course_id) #返回当前表的查看页面 Return Redirect (Self.get_list_url ()) #新的url, click on the corresponding course will go to this URL, this is only a separate URL for the customer to add Def extra_url (self): Temp = [] Temp.append (URL (r "cancel_course/(\d+)/(\d+)", Self.cancel_course)) return Tempsite.register (Customer, C Ustomerconfig)
In sites.py, we set a common Extra_url function, but the return is empty, so there is no cancel_course/(\d+)/(\d+) in the URL corresponding to the other table:
class ModelStark(): #配置类 def extra_url(self): return [] #我们在二级分发中将这条url添加到temp列表中 def get_urls2(self): #额外添加一个url temp.extend(self.extra_url()) return temp
Stark component 5_ Extension URL