chat qo'shildi
This commit is contained in:
1
core/apps/chat/admin/__init__.py
Normal file
1
core/apps/chat/admin/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .chat import * # noqa
|
||||
86
core/apps/chat/admin/chat.py
Normal file
86
core/apps/chat/admin/chat.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from unfold.admin import ModelAdmin
|
||||
|
||||
from core.apps.chat.models import ChatmessageModel, ChatroomModel
|
||||
|
||||
|
||||
@admin.register(ChatmessageModel)
|
||||
class ChatmessageAdmin(ModelAdmin):
|
||||
list_display = (
|
||||
"id",
|
||||
"room",
|
||||
"message_type",
|
||||
"sender",
|
||||
"short_text",
|
||||
"is_read",
|
||||
"created_at",
|
||||
)
|
||||
list_filter = ("message_type", "is_read", "created_at")
|
||||
search_fields = (
|
||||
"text",
|
||||
"sender__phone",
|
||||
"sender__first_name",
|
||||
"sender__last_name",
|
||||
)
|
||||
readonly_fields = ("created_at",)
|
||||
autocomplete_fields = ("sender",)
|
||||
ordering = ("-created_at",)
|
||||
fieldsets = (
|
||||
(
|
||||
_("Xabar"),
|
||||
{
|
||||
"fields": ("room", "sender", "message_type", "text", "file", "is_read"),
|
||||
},
|
||||
),
|
||||
(
|
||||
_("Tizim"),
|
||||
{
|
||||
"classes": ("collapse",),
|
||||
"fields": ("created_at",),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
@admin.display(description=_("Xabar"))
|
||||
def short_text(self, obj):
|
||||
if not obj.text:
|
||||
return f"[{obj.message_type}]"
|
||||
return obj.text[:60] + "..." if len(obj.text) > 60 else obj.text
|
||||
|
||||
|
||||
@admin.register(ChatroomModel)
|
||||
class ChatroomAdmin(ModelAdmin):
|
||||
list_display = (
|
||||
"id",
|
||||
"__str__",
|
||||
"type",
|
||||
"auto_evaluation",
|
||||
"created_at",
|
||||
)
|
||||
list_filter = ("type",)
|
||||
search_fields = ("auto_evaluation__id",)
|
||||
autocomplete_fields = ("auto_evaluation",)
|
||||
filter_horizontal = ("members",)
|
||||
readonly_fields = ("created_at", "updated_at")
|
||||
fieldsets = (
|
||||
(
|
||||
_("Xona"),
|
||||
{
|
||||
"fields": ("type", "auto_evaluation", "members"),
|
||||
},
|
||||
),
|
||||
(
|
||||
_("Tizim"),
|
||||
{
|
||||
"classes": ("collapse",),
|
||||
"fields": ("created_at", "updated_at"),
|
||||
},
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user