You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
786 B

9 years ago
9 years ago
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3. class SubscriptionManager(models.Manager):
  4. def for_user(self, user):
  5. sub, created = Subscription.objects.get_or_create(user_id=user.id)
  6. return sub
  7. class Subscription(models.Model):
  8. user = models.OneToOneField(User, blank=True, null=True)
  9. customer_id = models.CharField(max_length=36, blank=True)
  10. payment_method_token = models.CharField(max_length=35, blank=True)
  11. subscription_id = models.CharField(max_length=10, blank=True)
  12. plan_id = models.CharField(max_length=10, blank=True)
  13. objects = SubscriptionManager()
  14. def price(self):
  15. if self.plan_id == "P5":
  16. return 5
  17. elif self.plan_id == "P20":
  18. return 20
  19. return 0