text: from __future__ import unicode_literals
  
  from django.contrib import admin
  from django.contrib.auth.models import User, Group
  from django.db.models import Count
  
  from .models import Item, OrderItem, Order, Payment, Coupon, Refund
  
  
  def make_refund_accepted(modeladmin, request, queryset):
      queryset.update(refund_requested=False, refund_granted=True)
  
  
  make_refund_accepted.short_description = "Update orders to refund granted"
  
  
  class OrderAdmin(admin.ModelAdmin):
      list_display = [
          "user",
          "ordered",
          "being_delivered",
          "received",
          "refund_requested",
          "refund_granted",
          "billing_address",
          "payment",
          "coupon",
      ]
      list_display_links = ["user", "billing_address", "payment", "coupon"]
      list_filter = [
          "ordered",
          "being_delivered",
          "received",
          "refund_requested",
          "refund_granted",
      ]
      search_fields = ["user__username", "ref_code"]
      actions = [make_refund_accepted]
  
      list_per_page = 5
  
      def get_queryset(self, request):
  
          queryset = super().get_queryset(request)
          queryset = queryset.annotate(
              _user_count=Count("user", distinct=True),
              _ordered_count=Count("ordered", distinct=True),
          )
          return queryset
  
      def user_count(self, obj):
  
          return obj._user_count
  
      def ordered_count(self, obj):
  
          return obj._ordered_count
  
  
  class OrderItemAdmin(admin.ModelAdmin):
  
      list_display = ["user", "ordered", "item", "quantity"]
  
      list_per_page = 5
  
  
  admin.site.site_header = "Etalase Cetak"
  admin.site.site_title = "Etalase Cetak"
  admin.site.index_title = "Administrasi untuk Vendor/Pemesan"
  
  admin.site.register(Item)
  admin.site.register(OrderItem, OrderItemAdmin)
  admin.site.register(Order, OrderAdmin)
  admin.site.register(Payment)
  admin.site.register(Coupon)
  admin.site.register(Refund)
  
  admin.site.unregister(Group)
  