Fixed admin forms for Metric/KnobCatalog models.

This commit is contained in:
dvanaken 2020-01-13 15:38:42 -05:00 committed by Dana Van Aken
parent ee101d818e
commit e1a41928f6
1 changed files with 19 additions and 0 deletions

View File

@ -15,6 +15,7 @@ from .models import (BackupData, DBMSCatalog, KnobCatalog,
PipelineData, PipelineRun, Project, PipelineData, PipelineRun, Project,
Result, Session, Workload, Hardware, Result, Session, Workload, Hardware,
SessionKnob) SessionKnob)
from .types import VarType
class DBMSCatalogAdmin(admin.ModelAdmin): class DBMSCatalogAdmin(admin.ModelAdmin):
@ -26,12 +27,30 @@ class KnobCatalogAdmin(admin.ModelAdmin):
list_filter = (('dbms', admin.RelatedOnlyFieldListFilter), 'tunable') list_filter = (('dbms', admin.RelatedOnlyFieldListFilter), 'tunable')
ordering = ('dbms', '-tunable', 'name') ordering = ('dbms', '-tunable', 'name')
def get_form(self, request, obj=None, **kwargs):
exclude = ['category', 'summary', 'description', 'context']
if obj:
if obj.vartype not in (VarType.INTEGER, VarType.REAL):
exclude += ['minval', 'maxval']
if obj.vartype != VarType.ENUM:
exclude.append('enumvals')
kwargs['exclude'] = exclude
form = super().get_form(request, obj, **kwargs)
for field_name in ('minval', 'maxval', 'enumvals'):
if field_name in form.base_fields:
form.base_fields[field_name].required = False
return form
class MetricCatalogAdmin(admin.ModelAdmin): class MetricCatalogAdmin(admin.ModelAdmin):
list_display = ('name', 'dbms', 'metric_type') list_display = ('name', 'dbms', 'metric_type')
list_filter = (('dbms', admin.RelatedOnlyFieldListFilter), 'metric_type') list_filter = (('dbms', admin.RelatedOnlyFieldListFilter), 'metric_type')
ordering = ('dbms', 'name') ordering = ('dbms', 'name')
def get_form(self, request, obj=None, **kwargs):
kwargs['exclude'] = ('summary',)
return super().get_form(request, obj, **kwargs)
class ProjectAdmin(admin.ModelAdmin): class ProjectAdmin(admin.ModelAdmin):
list_display = ('name', 'user', 'last_update', 'creation_time') list_display = ('name', 'user', 'last_update', 'creation_time')