Skip to content

Commit

Permalink
Abstract product class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan committed Feb 28, 2023
1 parent 45d6293 commit 093c178
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def generate_fake_file(original_name):
return file


class Subscription(models.Model):
class ProductBase(models.Model):
title = models.CharField(
_('Title'),
max_length=128,
Expand Down Expand Up @@ -544,14 +544,21 @@ def get_internal_info(self, user: User):
if not is_available:
return {
'is_available': is_available,
'message': _('This subscription already yours!'),
'message': _('This product already yours!'),
}

return {
'is_available': is_available,
'message': _('Subscription is available!'),
'message': _('Product is available!'),
}

class Meta:
abstract = True


class Subscription(ProductBase):
pass


def get_payment_hex():
"""Generates UUID4 hex for payment_hex field."""
Expand Down
6 changes: 3 additions & 3 deletions accounts/templatetags/accounts_extras.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django import template

from accounts.models import Subscription, User
from accounts.models import ProductBase, User

register = template.Library()


@register.simple_tag
def get_product_internal_info(subscription: Subscription, user: User):
return subscription.get_internal_info(user)
def get_product_internal_info(product: ProductBase, user: User):
return product.get_internal_info(user)

0 comments on commit 093c178

Please sign in to comment.