class UpdateRow(tables.Row): ajax = True def get_data(self, request, instance_id): project_info = api.nova.server_get(request, instance_id) return project_info class UpdateCell(tables.UpdateAction): def allowed(self, request, instance, cell): policy_rule = (("identity", "identity:update_project"),) return True def update_cell(self, request, datum, instance_id,cell_name, new_cell_value): # inline update project info instance_obj = datum # updating changed value by new value setattr(instance_obj, cell_name, new_cell_value) api.nova.server_update(request,instance_id,name=instance_obj.name) //from openstack_dashboard import api return True
在定义字段的部分做如下修改:
name = tables.Column("name", verbose_name=_("Name"),form_field=forms.CharField(max_length=64),update_action=UpdateCell) //form_field也是新加的,同时要:from horizon import forms
class Meta:类中新加
row_class = UpdateRow //引用上面的UpdateRow