Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change a task with labels and attributes in admin panel #157

Merged
merged 2 commits into from
Oct 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)