74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
from django.contrib import admin
|
|
from .models import TicketIssueType, TicketAttachment, Tickets, Feedback, ContactUs
|
|
|
|
|
|
class FeedbackAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "principal", "email", "rating", "short_comment")
|
|
list_filter = ("rating", "principal")
|
|
search_fields = ("email", "comment")
|
|
readonly_fields = ("email",)
|
|
|
|
def short_comment(self, obj):
|
|
"""Create a shortened version of the comment for display in the list."""
|
|
return obj.comment[:50] + "..." if len(obj.comment) > 50 else obj.comment
|
|
|
|
short_comment.short_description = "Comment"
|
|
|
|
|
|
class ContactUsAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"name",
|
|
"email_address",
|
|
"mobile_number",
|
|
"subject",
|
|
"short_message",
|
|
"has_reply",
|
|
)
|
|
list_filter = ("subject",)
|
|
search_fields = ("name", "email_address", "mobile_number", "message")
|
|
readonly_fields = ("name", "email_address", "mobile_number", "subject", "message")
|
|
|
|
def short_message(self, obj):
|
|
"""Create a shortened version of the message for display in the list."""
|
|
return obj.message[:50] + "..." if len(obj.message) > 50 else obj.message
|
|
|
|
short_message.short_description = "Message"
|
|
|
|
def has_reply(self, obj):
|
|
"""Indicate whether the contact request has been replied to."""
|
|
return obj.reply is not None
|
|
|
|
has_reply.boolean = True
|
|
has_reply.short_description = "Replied?"
|
|
|
|
|
|
class TicketIssueTypeAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "name")
|
|
search_fields = ("name",)
|
|
|
|
|
|
class TicketAttachmentAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "image")
|
|
search_fields = ("image",)
|
|
|
|
|
|
class TicketsAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"id",
|
|
"issuetype",
|
|
"principal",
|
|
"subject",
|
|
"ticket_status",
|
|
"is_stopped",
|
|
)
|
|
list_filter = ("issuetype", "ticket_status", "is_stopped")
|
|
search_fields = ("subject", "description")
|
|
filter_horizontal = ("attachments",) # For the many-to-many relationship
|
|
|
|
|
|
admin.site.register(ContactUs, ContactUsAdmin)
|
|
admin.site.register(Feedback, FeedbackAdmin)
|
|
admin.site.register(TicketIssueType, TicketIssueTypeAdmin)
|
|
admin.site.register(TicketAttachment, TicketAttachmentAdmin)
|
|
admin.site.register(Tickets, TicketsAdmin)
|