From 3728d1101fa117e0f0cb2b4bcd0e2e93b9290301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Wed, 10 Jan 2018 15:35:34 +0200 Subject: [PATCH] Payments admin tweaks --- hc/payments/admin.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/hc/payments/admin.py b/hc/payments/admin.py index 309339e9..ade2c94a 100644 --- a/hc/payments/admin.py +++ b/hc/payments/admin.py @@ -1,12 +1,18 @@ from django.contrib import admin -from .models import Subscription +from django.core.urlresolvers import reverse +from hc.accounts.models import Profile +from hc.payments.models import Subscription @admin.register(Subscription) class SubsAdmin(admin.ModelAdmin): - list_display = ("id", "email", "customer_id", - "payment_method_token", "subscription_id", "plan_id") + readonly_fields = ("email", ) + search_fields = ("customer_id", "payment_method_token", "subscription_id", + "user__email") + list_display = ("id", "email", "customer_id", "address_id", + "payment_method_token", "subscription_id", "plan_id", + "profile") list_filter = ("plan_id", ) actions = ("cancel", ) @@ -14,8 +20,24 @@ class SubsAdmin(admin.ModelAdmin): def email(self, obj): return obj.user.email if obj.user else None + def profile(self, obj): + if obj.user.profile: + url = reverse("admin:accounts_profile_change", + args=[obj.user.profile.id]) + return "View Profile" % url + + return "" + + profile.allow_tags = True + def cancel(self, request, qs): for sub in qs.all(): sub.cancel() + profile = Profile.objects.for_user(sub.user) + profile.check_limit = 20 + profile.team_limit = 2 + profile.sms_limit = 0 + profile.save() + self.message_user(request, "%d subscriptions cancelled" % qs.count())