2012-03-05 72 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()