From c183b360ff07673f00d0f4f224ced3c46fd87381 Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Wed, 18 Apr 2018 08:57:12 +1200 Subject: 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 --- layerindex/admin.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/layerindex/admin.py b/layerindex/admin.py index 7e93674ade..aed9a5d961 100644 --- a/layerindex/admin.py +++ b/layerindex/admin.py @@ -89,7 +89,12 @@ class LayerUpdateAdmin(admin.ModelAdmin): class RecipeAdmin(admin.ModelAdmin): search_fields = ['filename', 'pn'] 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): return False def has_delete_permission(self, request, obj=None): @@ -110,7 +115,12 @@ class DynamicBuildDepAdmin(admin.ModelAdmin): class ClassicRecipeAdmin(admin.ModelAdmin): search_fields = ['filename', 'pn'] 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): return False def has_delete_permission(self, request, obj=None): -- cgit 1.2.3-korg