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.

32 lines
876 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. try:
  6. sub = self.get(user_id=user.id)
  7. except Subscription.DoesNotExist:
  8. sub = Subscription(user=user)
  9. sub.save()
  10. return sub
  11. class Subscription(models.Model):
  12. user = models.OneToOneField(User, blank=True, null=True)
  13. customer_id = models.CharField(max_length=36, blank=True)
  14. payment_method_token = models.CharField(max_length=35, blank=True)
  15. subscription_id = models.CharField(max_length=10, blank=True)
  16. plan_id = models.CharField(max_length=10, blank=True)
  17. objects = SubscriptionManager()
  18. def price(self):
  19. if self.plan_id == "P5":
  20. return 5
  21. elif self.plan_id == "P20":
  22. return 20
  23. return 0