Skip to content

Commit

Permalink
feat: add subscription to django admin (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Nov 24, 2023
1 parent 212eab8 commit 4fb33a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bd_api/apps/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from faker import Faker

from bd_api.apps.account.models import Account, BDGroup, BDGroupRole, BDRole, Career
from bd_api.apps.account.models import Account, BDGroup, BDGroupRole, BDRole, Career, Subscription


class AccountCreationForm(forms.ModelForm):
Expand Down Expand Up @@ -228,7 +228,18 @@ class BDGroupAdmin(admin.ModelAdmin):
ordering = ("name",)


class SubscriptionAdmin(admin.ModelAdmin):
list_display = (
"admin_name",
"stripe_subscription",
"stripe_subscription_status",
)
search_fields = ("admin__full_name",)
ordering = ("admin__full_name",)


admin.site.register(Account, AccountAdmin)
admin.site.register(Career, CareerAdmin)
admin.site.register(BDRole)
admin.site.register(BDGroup, BDGroupAdmin)
admin.site.register(Subscription, SubscriptionAdmin)
22 changes: 22 additions & 0 deletions bd_api/apps/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,25 @@ class Subscription(BdmModel):
class Meta:
verbose_name = "Subscription"
verbose_name_plural = "Subscriptions"

@property
def admin_name(self):
return f"{self.admin.first_name} {self.admin.last_name}"

@property
def stripe_subscription(self):
try:
customer = self.admin.djstripe_customers.first()
product = customer.subscription.plan.product.name
return product
except Exception:
return ""

@property
def stripe_subscription_status(self):
try:
customer = self.admin.djstripe_customers.first()
status = customer.subscription.status
return status
except Exception:
return ""

0 comments on commit 4fb33a7

Please sign in to comment.