from sets.admin import *
from .models import *
from django.contrib import admin
from django import forms
from django.forms import widgets




class Admin_MsgGroup(Admin_BaseModel):
    list_display = [
        'id', 'department', 'name', 'status', 'owner', 'manager', 'text',
        'order', 'modifiedDT', 'createDT'
    ]

admin.site.register(MsgGroup,Admin_MsgGroup)

class Admin_Message(Admin_BaseModel):

    def cut_group_text(self, obj):
        if obj.group:
            return obj.group.name[:10]
        return '-'
    cut_group_text.allow_tags = True
    cut_group_text.short_description = 'ticket'


    def cut_text(self, obj):
        if obj.text:
            if len(obj.text) > 20:
                return f'{obj.text[:20]}...'
            else:
                return obj.text
        return '-'
    cut_text.allow_tags = True
    cut_text.short_description = 'сообщение'

    search_fields = ['group__name', 'text', 'name', 'id']

    list_filter = ['status']

    list_display = [
        'id',
        # 'msg_type',
        'cut_group_text', 'status', 'sender', 'receiver', 'cut_text',
        'name',
        'order', 'modifiedDT', 'createDT'
    ]

admin.site.register(Message,Admin_Message)