# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django_services import admin
from ..models import Maintenance
from ..service.maintenance import MaintenanceService
from ..forms import MaintenanceForm


class MaintenanceAdmin(admin.DjangoServicesAdmin):
    service_class = MaintenanceService
    search_fields = ("scheduled_for", "description", "maximum_workers", 'status')
    list_display = ("scheduled_for", "description", "maximum_workers", 'status')
    fields = ( "description", "scheduled_for", "main_script", "rollback_script",
         "host_query","maximum_workers", "status", "celery_task_id",)
    save_on_top = True
    readonly_fields = ('status', 'celery_task_id')
    form = MaintenanceForm

    def change_view(self, request, object_id, form_url='', extra_context=None):
        maintenance = Maintenance.objects.get(id=object_id)

        if maintenance.celery_task_id:
            self.readonly_fields = self.fields

        return super(MaintenanceAdmin, self).change_view(request,
            object_id, form_url, extra_context=extra_context)



@@ -112,41 +112,8 @@
 min%0A
-from ..models import Maintenance%0A
 from
@@ -634,224 +634,141 @@
     
-readonly_fields = ('status', 'celery_task_id')%0A    form = MaintenanceForm%0A%0A    def change_view(self, request, object_id, form_url='', extra_context=None):%0A        maintenance = Maintenance.objects.get(id=object_id)%0A%0A
+form = MaintenanceForm%0A%0A    def get_readonly_fields(self, request, obj=None):%0A        maintenance = obj%0A%0A        if maintenance:%0A    
     
@@ -818,30 +818,18 @@
     
-self.readonly_fields =
+    return
  sel
@@ -857,119 +857,36 @@
 urn 
-super(MaintenanceAdmin, self).change_view(request,%0A            object_id, form_url, extra_context=extra_context
+('status', 'celery_task_id',
 )%0A%0A%0A

Add get_read_only and remove old change_view customization