From d4cb96f4fd6c527e2cff2223e1ced4576be1e6ae Mon Sep 17 00:00:00 2001 From: Roland Szabo Date: Tue, 6 Jul 2021 14:21:13 +0300 Subject: [PATCH] Add admin interface for AutoLabelingConfigs. Solves #1423 Thanks to @uklft for the idea. --- backend/api/admin.py | 15 ++++++++++++++- backend/api/models.py | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/api/admin.py b/backend/api/admin.py index bd4a1dfd..1e7d4fc5 100644 --- a/backend/api/admin.py +++ b/backend/api/admin.py @@ -2,7 +2,8 @@ from django.contrib import admin from .models import (Category, Comment, Example, Label, Project, Role, RoleMapping, Seq2seqProject, SequenceLabelingProject, - Span, Tag, TextClassificationProject, TextLabel) + Span, Tag, TextClassificationProject, TextLabel, + AutoLabelingConfig) class LabelAdmin(admin.ModelAdmin): @@ -62,6 +63,18 @@ class CommentAdmin(admin.ModelAdmin): search_fields = ('user',) +class AutoLabelingConfigAdmin(admin.ModelAdmin): + list_display = ('project', 'model_name', 'model_attrs',) + ordering = ('project',) + + def get_readonly_fields(self, request, obj=None): + if obj: + return ["model_name"] + else: + return [] + + +admin.site.register(AutoLabelingConfig, AutoLabelingConfigAdmin) admin.site.register(Category, CategoryAdmin) admin.site.register(Span, SpanAdmin) admin.site.register(TextLabel, TextLabelAdmin) diff --git a/backend/api/models.py b/backend/api/models.py index 18d52f45..a27d05a4 100644 --- a/backend/api/models.py +++ b/backend/api/models.py @@ -339,7 +339,7 @@ class AutoLabelingConfig(models.Model): model_name = models.CharField(max_length=100) model_attrs = models.JSONField(default=dict) template = models.TextField(default='') - label_mapping = models.JSONField(default=dict) + label_mapping = models.JSONField(default=dict, blank=True) project = models.ForeignKey( to=Project, on_delete=models.CASCADE,