Reputation: 1286
I'm currently trying to wrap my head around setting up a payment system for one of my apps. I'm going with braintree and currently I have three different models handling payment/subscription.
One of them being 'Transaction' which im thinking should hold all the info I recieve from braintree. So I set my model up like this:
class Transaction(models.Model):
created_at = models.DateField(auto_now_add=True)
subscription = models.ForeignKey(Subscription)
braintree_transaction_info = models.OneToOneField('braintree.Transaction')
def __unicode__(self):
return '{0}, at {1}'.format(self.subscription.user, self.date)
However I'm getting the error:
core.Transaction.braintree_transaction_info: (fields.E300) Field defines a relation with model 'braintree.Transaction', which is either not installed, or is abstract.
So my question is how can I store the braintree transaction data in my model. Do I even need it? Or can I fetch it some other way at a later stage.
Upvotes: 1
Views: 306
Reputation: 916
braintree.Transaction is not a Django model with a corresponding table in your DB. You can't establish a DB relation with it. braintree.Transaction is really just giving your Python app a handy way to interact with the Braintree Transaction API.
What you can do is create a charfield to track the transaction ID on braintree. You can enforce that this field is unique, so that you only have 0..1 Transaction records for each Braintree Transaction. You can then create a property on your Transaction or you could create a custom object manager that transparently accesses Braintree as needed via braintree.Transaction's methods.
Upvotes: 1