admin: use more dynamic method of setting recipe read-only fields

Every time we add something that links to Recipe we had to add it to the
exclusions list in the readonly_fields line for RecipeAdmin (and
ClassicRecipeAdmin), which is tedious and easily forgotten. We can avoid
this by looking at each field and excluding it by its attributes rather
than having a hardcoded list of names.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-04-18 08:57:12 +12:00
parent 9ebc94a1df
commit c183b360ff

View File

@ -89,7 +89,12 @@ class LayerUpdateAdmin(admin.ModelAdmin):
class RecipeAdmin(admin.ModelAdmin): class RecipeAdmin(admin.ModelAdmin):
search_fields = ['filename', 'pn'] search_fields = ['filename', 'pn']
list_filter = ['layerbranch__layer__name', 'layerbranch__branch__name'] list_filter = ['layerbranch__layer__name', 'layerbranch__branch__name']
readonly_fields = [f.name for f in Recipe._meta.get_fields() if f.name not in ['recipefiledependency', 'classicrecipe', 'packageconfig']] def get_readonly_fields(self, request, obj=None):
rofields = []
for f in Recipe._meta.get_fields():
if not (f.auto_created and f.is_relation):
rofields.append(f.name)
return rofields
def has_add_permission(self, request, obj=None): def has_add_permission(self, request, obj=None):
return False return False
def has_delete_permission(self, request, obj=None): def has_delete_permission(self, request, obj=None):
@ -110,7 +115,12 @@ class DynamicBuildDepAdmin(admin.ModelAdmin):
class ClassicRecipeAdmin(admin.ModelAdmin): class ClassicRecipeAdmin(admin.ModelAdmin):
search_fields = ['filename', 'pn'] search_fields = ['filename', 'pn']
list_filter = ['layerbranch__layer__name', 'layerbranch__branch__name'] list_filter = ['layerbranch__layer__name', 'layerbranch__branch__name']
readonly_fields = [f.name for f in ClassicRecipe._meta.get_fields() if f.name not in ['recipefiledependency', 'packageconfig']] def get_readonly_fields(self, request, obj=None):
rofields = []
for f in ClassicRecipe._meta.get_fields():
if not (f.auto_created and f.is_relation):
rofields.append(f.name)
return rofields
def has_add_permission(self, request, obj=None): def has_add_permission(self, request, obj=None):
return False return False
def has_delete_permission(self, request, obj=None): def has_delete_permission(self, request, obj=None):