ticket model and admin add ticket category

This commit is contained in:
Parsa Nazer
2025-02-15 00:04:51 +03:30
parent 9cdd903eac
commit 00b5ce5a6c
6 changed files with 79 additions and 6 deletions
+12 -4
View File
@@ -6,6 +6,13 @@ from import_export.admin import ImportExportModelAdmin
from unfold.contrib.import_export.forms import ExportForm, ImportForm, SelectableFieldsExportForm
from unfold.contrib.forms.widgets import ArrayWidget, WysiwygWidget
from django.contrib.postgres.fields import ArrayField
from unfold.contrib.filters.admin import (
ChoicesDropdownFilter,
MultipleChoicesDropdownFilter,
)
class MessageInline(TabularInline):
model = Message
@@ -16,9 +23,9 @@ class TicketAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
search_fields = ['subject',]
list_filter = ['status']
search_fields = ['subject', 'messages__content']
list_filter = [('status', ChoicesDropdownFilter), ('ticket_category', ChoicesDropdownFilter)]
list_filter_submit = True
compressed_fields = True
warn_unsaved_form = True
@@ -27,7 +34,8 @@ class TicketAdmin(ModelAdmin, ImportExportModelAdmin):
"widget": ArrayWidget,
}
}
list_display = ['subject', 'customer', 'admin', 'status', 'admin', 'status', 'created_at']
readonly_fields = ('created_at', 'updated_at')
list_display = ['subject', 'ticket_category', 'customer', 'admin', 'status', 'created_at']
inlines = [MessageInline]
radio_fields = {'status': admin.VERTICAL}
@@ -0,0 +1,19 @@
# Generated by Django 5.1.2 on 2025-02-13 21:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ticket', '0004_alter_message_content_alter_message_created_at_and_more'),
]
operations = [
migrations.AddField(
model_name='ticket',
name='ticket_category',
field=models.CharField(default='other', max_length=30, verbose_name='دسته بندی تیکت'),
preserve_default=False,
),
]
@@ -0,0 +1,18 @@
# Generated by Django 5.1.2 on 2025-02-13 21:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ticket', '0005_ticket_ticket_category'),
]
operations = [
migrations.AlterField(
model_name='ticket',
name='ticket_category',
field=models.CharField(choices=[('finance_and_accounting', 'مالی و حسابداری - Finance and Accounting'), ('user_profile', 'پروفایل کاربری - User Profile'), ('order_tracking', 'پیگیری سفارش - Order Tracking'), ('authentication', 'احراز هویت - Authentication'), ('product', 'محصول - Product'), ('bug_reporting', 'اعلام باگ و خطا در وبسایت - Bug and Error Reporting'), ('other', 'سایر - Other')], max_length=30, verbose_name='دسته بندی تیکت'),
),
]
@@ -0,0 +1,18 @@
# Generated by Django 5.1.2 on 2025-02-13 21:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ticket', '0006_alter_ticket_ticket_category'),
]
operations = [
migrations.AlterField(
model_name='ticket',
name='ticket_category',
field=models.CharField(choices=[('Finance and Accounting', 'مالی و حسابداری'), ('User Profile', 'پروفایل کاربری'), ('Order Tracking', 'پیگیری سفارش'), ('Authentication', 'احراز هویت'), ('Product', 'محصول'), ('Bug and Error Reporting', 'اعلام باگ و خطا در وبسایت'), ('Other', 'سایر')], max_length=30, verbose_name='دسته بندی تیکت'),
),
]
+10 -1
View File
@@ -8,8 +8,17 @@ class Ticket(models.Model):
('resolved', 'حل شده'),
('closed', 'بسته'),
]
CATEGORY_CHOICES = [
('finance_and_accounting', 'مالی و حسابداری'),
('user_profile', 'پروفایل کاربری'),
('order_tracking', 'پیگیری سفارش'),
('authentication', 'احراز هویت'),
('product', 'محصول'),
('bug_and_error_reporting', 'اعلام باگ و خطا در وبسایت'),
('other', 'سایر'),
]
subject = models.CharField(max_length=255, verbose_name='موضوع')
ticket_category = models.CharField(max_length=30, verbose_name='دسته بندی تیکت', choices=CATEGORY_CHOICES)
customer = models.ForeignKey(User, on_delete=models.CASCADE, related_name="tickets", verbose_name='کاربر')
admin = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True, related_name="assigned_tickets", verbose_name='ادمین')
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='open', verbose_name='وضعیت تیکت')