I have two models, Transaction and Subscription. Transaction has a FK to Subscription with the related name="subscription_transaction". I am trying to query the transaction.amount on a SubscriptionDetailView. Why is my template query not working.
Neither work
subscription_detail.html
<td class="text-dark ">{{ subscription.subscription_transaction.timestamp.all }}</td
<td class="text-dark"> {{ subscription.subscription_transaction.amount }}</td>`
models.py
class Subscription(models.Model):
id = models.CharField(max_length=36, unique=True, default=uuid.uuid4, primary_key=True, editable=False)
user_membership = models.ForeignKey(UserMembership, on_delete=models.CASCADE)
stripe_subscription_id = models.CharField(max_length=40)
active = models.BooleanField(default=True)
def __str__(self):
return self.user_membership.user.username
@property
def get_created_date(self):
subscription = stripe.Subscription.retrieve(self.stripe_subscription_id)
return datetime.fromtimestamp(subscription.created)
@property
def get_next_billing_date(self):
subscription = stripe.Subscription.retrieve(self.stripe_subscription_id)
return datetime.fromtimestamp(subscription.current_period_end)
class Transaction(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="user_transaction")
order_id = models.CharField(max_length=36, unique=True, default=uuid.uuid4, primary_key=True, editable=False)
subscription = models.ForeignKey(Subscription, on_delete=models.SET_NULL, null=True, blank=True, related_name="subscription_transaction")
amount = models.DecimalField(max_digits=100, decimal_places=2)
success = models.BooleanField(default=True)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)