Skip to content

Commit

Permalink
Change a task with labels and attributes in admin panel (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanovic authored Oct 25, 2018
1 parent ae77993 commit 2816657
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion cvat/apps/engine/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,66 @@
# SPDX-License-Identifier: MIT

from django.contrib import admin
from .models import Task, Segment, Label, AttributeSpec

# Register your models here.
class SegmentInline(admin.TabularInline):
model = Segment
readonly_fields = ('start_frame', 'stop_frame')
can_delete = False

# Don't show on admin index page
def has_add_permission(self, request, object=None):
return False

class AttributeSpecInline(admin.TabularInline):
model = AttributeSpec
extra = 0
max_num = None

class LabelInline(admin.TabularInline):
model = Label
show_change_link = True
extra = 0
max_num = None

class LabelAdmin(admin.ModelAdmin):
# Don't show on admin index page
def has_module_permission(self, request):
return False

inlines = [
AttributeSpecInline
]


class TaskAdmin(admin.ModelAdmin):
date_hierarchy = 'updated_date'
readonly_fields = ('size', 'path', 'created_date', 'updated_date',
'overlap', 'flipped')
list_display = ('name', 'mode', 'owner', 'created_date', 'updated_date')
search_fields = ('name', 'mode', 'owner_username', 'owner_first_name',
'owner_last_name', 'owner_email')
inlines = [
SegmentInline,
LabelInline
]

# A callable object to use inside search_fields
def owner_first_name(self, obj):
return obj.owner.first_name

# A callable object to use inside search_fields
def owner_last_name(self, obj):
return obj.owner.last_name

# A callable object to use inside search_fields
def owner_email(self, obj):
return obj.owner.email

# Don't allow to add a task because it isn't trivial operation
def has_add_permission(self, request):
return False


admin.site.register(Task, TaskAdmin)
admin.site.register(Label, LabelAdmin)

0 comments on commit 2816657

Please sign in to comment.