2012-03-05 76 views
0

在Django的管理模式變更列表頁我想與其他型號also.I平均互動,自定義Django管理變更列表頁面

我有三個型號

1.Keywords 

     contains name field 

    2.Category 
     contains category_name field 

    3.Keyword Category Relation 
     Category is ForeignKey and Keyword is Many to many field 

在我的關鍵字模式的變更表。 html頁面,我需要定製,這些變化將是

There should be a dropdown box which lists all category model objects 

如果我選擇一些關鍵字,並選擇從下拉列表中特定類別下來,擊中保存按鈕的關鍵字和CA時需要在另一個模型中更新服裝

應該如何進行?它應該怎麼做?建議我

回答

0

您可以覆蓋save_model和save_formset函數。例病例來自我自己的代碼(admin.py):

class SubtaskAdmin(admin.ModelAdmin): 
    form = SubtaskAdminForm 
    list_display = ('id', 'task', 'date_created', 'author', 'status', 'is_reclamation') 
    list_filter = ('date_created', 'status', 'is_reclamation') 
    actions = [change_subtask_status_to_new, change_subtask_status_to_open, change_subtask_status_to_ready] 
    fields = ('order', 'task', 'tags', 'amount', 'is_reclamation', 'status') 

    def save_model(self, request, obj, form, change): 
     if not change: 
      employee = Employee.objects.get(id=request.user.id) 
      obj.author = employee 
     obj.save() 
     super(SubtaskAdmin, self).save_model(request, obj, form, change) 

...

class MaintenanceOrderLineAdmin(admin.ModelAdmin): 
     ... 
     def save_formset(self, request, form, formset, change): 
       instances = formset.save(commit=False) 
       employee = get_object_or_404(Employee, id=request.user.id) 
       for instance in instances: 
        if isinstance(instance, Subtask): 
         instance.author = employee 
         instance.save()