signal of address and some model udapte send address filed of an order
This commit is contained in:
+15
-13
@@ -1,7 +1,7 @@
|
||||
from django.contrib import admin, messages
|
||||
from .models import *
|
||||
from unfold.admin import TabularInline, StackedInline
|
||||
|
||||
from django.db.models import Q
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from unfold.contrib.import_export.forms import ExportForm, ImportForm, SelectableFieldsExportForm
|
||||
from unfold.contrib.forms.widgets import ArrayWidget, WysiwygWidget
|
||||
@@ -47,11 +47,11 @@ class BankRecordInline(StackedInline):
|
||||
class OrderAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
import_form_class = ImportForm
|
||||
export_form_class = ExportForm
|
||||
search_fields = ['order_id', 'user__phone', 'user__first_name', 'user__last_name', 'user__email']
|
||||
search_fields = ['user__phone', 'user__first_name', 'user__last_name', 'user__email']
|
||||
list_filter = ['is_paid', 'status']
|
||||
actions_list = ['redirect_to_learn', 'udpate_bank_status']
|
||||
list_display = ['order_id', 'user', 'is_paid', 'status', 'discount_code', 'address',]
|
||||
readonly_fields = ('created_at', 'order_id', 'tax', 'final_price', 'cart_total', 'discount', 'discount_code', 'user', 'address', 'is_paid')
|
||||
readonly_fields = ('created_at', 'tax', 'final_price', 'cart_total', 'discount_amount', 'discount_code', 'user', 'address', 'is_paid')
|
||||
compressed_fields = True
|
||||
warn_unsaved_form = True
|
||||
# exclude = ('bank_records',)
|
||||
@@ -61,19 +61,21 @@ class OrderAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
}
|
||||
}
|
||||
inlines = [OrderItemModelInline, BankRecordInline]
|
||||
# def bank_links(self, obj):
|
||||
# banks = obj.bank_records.all()
|
||||
def order_id(self, obj):
|
||||
return f"سفارش {obj.pk + 1000}"
|
||||
order_id.short_description = "شماره سفارش"
|
||||
|
||||
# if not banks.exists():
|
||||
# return "-"
|
||||
|
||||
# return format_html_join(
|
||||
# "",
|
||||
# '<a style="padding-bottom:10px;display:block;" href="/secret-admin/azbankgateways/bank/{}/change/" class="text-primary-600 dark:text-primary-500">{}</a>',
|
||||
# [(bank.id, bank.tracking_code) for bank in banks]
|
||||
# ) or "-"
|
||||
|
||||
# bank_links.short_description = "Bank Records"
|
||||
def get_search_results(self, request, queryset, search_term):
|
||||
queryset, use_distinct = super().get_search_results(request, queryset, search_term)
|
||||
|
||||
|
||||
if search_term.isdigit():
|
||||
order_id_search = int(search_term) - 1000
|
||||
queryset |= self.model.objects.filter(Q(pk=order_id_search))
|
||||
|
||||
return queryset, use_distinct
|
||||
|
||||
@action(description='اپدیت وضعیت رکورد های بانکی')
|
||||
def udpate_bank_status(self, request):
|
||||
|
||||
Reference in New Issue
Block a user