from django.contrib import admin from core.apps.orders.models import DeletedParty, Party, PartyAmount class PartyAmountInline(admin.StackedInline): model = PartyAmount extra = 1 show_change_link = True @admin.register(Party) class PartyAdmin(admin.ModelAdmin): list_display = [ "id", "number", "party_amount__total_price", 'party_amount__calculated_amount', 'party_amount__paid_amount', "currency", 'process', 'payment_percentage', ] inlines = [PartyAmountInline] search_fields = [ "number", "orders__counterparty__name" ] autocomplete_fields = ['orders'] ordering = ['-number'] def get_queryset(self, request): return super().get_queryset(request).select_related('party_amount', 'mediator').prefetch_related('orders') @admin.register(PartyAmount) class PartyAmountAdmin(admin.ModelAdmin): list_display = ["id", "total_price", "cost_amount"] def has_module_permission(self, request): return False @admin.register(DeletedParty) class DeletedPartyAdmin(admin.ModelAdmin): list_display = ["id", "deleted_date", "party"]