fix bug where change instance before add instance would lead to keyerror; juggle the instance fields around
diff --git a/xos/core/admin.py b/xos/core/admin.py
index 9f6b9d3..b3dc67d 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -1265,7 +1265,7 @@
class InstanceAdmin(XOSBaseAdmin):
form = InstanceForm
fieldsets = [
- ('Instance Details', {'fields': ['backend_status_text', 'slice', 'deployment', 'node', 'all_ips_string', 'instance_id', 'instance_name', 'flavor', 'image', 'ssh_command', 'no_sync'], 'classes': ['suit-tab suit-tab-general'], })
+ ('Instance Details', {'fields': ['backend_status_text', 'slice', 'deployment', 'flavor', 'image', 'node', 'all_ips_string', 'instance_id', 'instance_name', 'ssh_command'], 'classes': ['suit-tab suit-tab-general'], })
]
readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string')
list_display = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'flavor', 'image', 'node', 'deployment']
@@ -1295,17 +1295,14 @@
# the slices they belong to.
return Instance.select_by_user(request.user)
+ def add_view(self, request, form_url='', extra_context = None):
+ self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string')
+ return super(InstanceAdmin,self).add_view(request, form_url, extra_context)
- def get_formsets(self, request, obj=None):
- # make some fields read only if we are updating an existing record
- if obj == None:
- self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string')
- else:
- self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string', 'slice', 'flavor', 'image', 'node')
-
- for inline in self.get_inline_instances(request, obj):
- # dead code was eliminated here
- yield inline.get_formset(request, obj)
+ def change_view(self, request, object_id, extra_context=None):
+ self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string', 'deployment', 'slice', 'flavor', 'image', 'node')
+ self.readonly_save = self.readonly_fields # for XOSAdminMixin.change_view's user_readonly_fields switching code
+ return super(InstanceAdmin,self).change_view(request, object_id, extra_context)
def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
deployment_nodes = []