From 855715f7e972edec62791d01c1a0d26a885aca1c Mon Sep 17 00:00:00 2001 From: Jacek Date: Fri, 30 Jun 2017 13:35:13 +0200 Subject: [PATCH] adding source for charge --- CHANGELOG.txt | 4 +++ aa_stripe/__init__.py | 2 +- .../migrations/0008_auto_20170630_0734.py | 27 +++++++++++++++++++ aa_stripe/models.py | 5 ++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 aa_stripe/migrations/0008_auto_20170630_0734.py diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7642b2d..66d3e4c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## [0.2.9] +### Added +- added GenericForeignKey to StripeCharge as "source" field. Use https://docs.djangoproject.com/en/1.11/ref/contrib/contenttypes/#reverse-generic-relations for reverse lookup. + ## [0.2.8] ### Changed - changed relation on stripe models from to settings.STRIPE_USER_MODEL, which defaults to settings.AUTH_USER_MODEL. There are cases that CC is connected to, in example, office, not person. diff --git a/aa_stripe/__init__.py b/aa_stripe/__init__.py index c75a3c0..c1329ab 100644 --- a/aa_stripe/__init__.py +++ b/aa_stripe/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- __title__ = "Arabella Stripe" -__version__ = "0.2.8" +__version__ = "0.2.9" __author__ = "Jacek Ostanski" __license__ = "MIT" __copyright__ = "Copyright 2017 Arabella" diff --git a/aa_stripe/migrations/0008_auto_20170630_0734.py b/aa_stripe/migrations/0008_auto_20170630_0734.py new file mode 100644 index 0000000..0194489 --- /dev/null +++ b/aa_stripe/migrations/0008_auto_20170630_0734.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-06-30 11:34 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('aa_stripe', '0007_auto_20170630_0557'), + ] + + operations = [ + migrations.AddField( + model_name='stripecharge', + name='content_type', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'), + ), + migrations.AddField( + model_name='stripecharge', + name='object_id', + field=models.PositiveIntegerField(db_index=True, null=True), + ), + ] diff --git a/aa_stripe/models.py b/aa_stripe/models.py index 5d959cb..bc30a9b 100644 --- a/aa_stripe/models.py +++ b/aa_stripe/models.py @@ -4,6 +4,8 @@ import simplejson as json import stripe from django.conf import settings +from django.contrib.contenttypes import fields as generic +from django.contrib.contenttypes.models import ContentType from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models from django.utils import timezone @@ -64,6 +66,9 @@ class StripeCharge(StripeBasicModel): stripe_charge_id = models.CharField(max_length=255, blank=True, db_index=True) description = models.CharField(max_length=255, help_text=_("Description sent to Stripe")) comment = models.CharField(max_length=255, help_text=_("Comment for internal information")) + content_type = models.ForeignKey(ContentType, null=True) + object_id = models.PositiveIntegerField(null=True, db_index=True) + source = generic.GenericForeignKey('content_type', 'object_id') def charge(self): if self.is_charged: