Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request dj-stripe#331 from cloudsmith-io/bugfix-incorrect-…
Browse files Browse the repository at this point in the history
…cascading

Fix cascading delete on models
  • Loading branch information
kavdev authored Jul 6, 2016
2 parents 095edf6 + 189262a commit 5cc9472
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
41 changes: 41 additions & 0 deletions djstripe/migrations/0017_set_null_on_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-07-05 12:04
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('djstripe', '0016_stripe_id_255_length'),
]

operations = [
migrations.AlterField(
model_name='customer',
name='default_source',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='customers', to='djstripe.StripeSource'),
),
migrations.AlterField(
model_name='charge',
name='source',
field=models.ForeignKey(help_text='The source used for this charge.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='charges', to='djstripe.StripeSource'),
),
migrations.AlterField(
model_name='invoice',
name='subscription',
field=models.ForeignKey(help_text='The subscription that this invoice was prepared for, if any.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoices', to='djstripe.Subscription'),
),
migrations.AlterField(
model_name='invoiceitem',
name='plan',
field=models.ForeignKey(help_text='If the invoice item is a proration, the plan of the subscription for which the proration was computed.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoiceitems', to='djstripe.Plan'),
),
migrations.AlterField(
model_name='invoiceitem',
name='subscription',
field=models.ForeignKey(help_text='The subscription that this invoice item has been created for, if any.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoiceitems', to='djstripe.Subscription'),
),
]
16 changes: 9 additions & 7 deletions djstripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class Charge(StripeCharge):
customer = models.ForeignKey("Customer", related_name="charges", help_text="The customer associated with this charge.")
transfer = models.ForeignKey("Transfer", null=True, help_text="The transfer to the destination account (only applicable if the charge was created using the destination parameter).")

source = models.ForeignKey(StripeSource, null=True, related_name="charges", help_text="The source used for this charge.")
source = models.ForeignKey(StripeSource, null=True, related_name="charges", on_delete=models.SET_NULL,
help_text="The source used for this charge.")

receipt_sent = models.BooleanField(default=False, help_text="Whether or not a receipt was sent for this charge.")

Expand Down Expand Up @@ -127,9 +128,7 @@ class Customer(StripeCustomer):

# account = models.ForeignKey(Account, related_name="customers")

default_source = models.ForeignKey(
StripeSource, null=True, related_name="customers",
on_delete=models.SET_NULL)
default_source = models.ForeignKey(StripeSource, null=True, related_name="customers", on_delete=models.SET_NULL)

subscriber = models.OneToOneField(getattr(settings, 'DJSTRIPE_SUBSCRIBER_MODEL', settings.AUTH_USER_MODEL), null=True)
date_purged = models.DateTimeField(null=True, editable=False)
Expand Down Expand Up @@ -558,7 +557,8 @@ class Invoice(StripeInvoice):
# account = models.ForeignKey("Account", related_name="invoices")
customer = models.ForeignKey(Customer, related_name="invoices", help_text="The customer associated with this invoice.")
charge = models.OneToOneField(Charge, null=True, related_name="invoice", help_text="The latest charge generated for this invoice, if any.")
subscription = models.ForeignKey("Subscription", null=True, related_name="invoices", help_text="The subscription that this invoice was prepared for, if any.")
subscription = models.ForeignKey("Subscription", null=True, related_name="invoices", on_delete=models.SET_NULL,
help_text="The subscription that this invoice was prepared for, if any.")

class Meta(object):
ordering = ["-date"]
Expand Down Expand Up @@ -663,8 +663,10 @@ class InvoiceItem(StripeInvoiceItem):
# account = models.ForeignKey(Account, related_name="invoiceitems")
customer = models.ForeignKey(Customer, related_name="invoiceitems", help_text="The customer associated with this invoiceitem.")
invoice = models.ForeignKey(Invoice, null=True, related_name="invoiceitems", help_text="The invoice to which this invoiceitem is attached.")
plan = models.ForeignKey("Plan", null=True, related_name="invoiceitems", help_text="If the invoice item is a proration, the plan of the subscription for which the proration was computed.")
subscription = models.ForeignKey("Subscription", null=True, related_name="invoiceitems", help_text="The subscription that this invoice item has been created for, if any.")
plan = models.ForeignKey("Plan", null=True, related_name="invoiceitems", on_delete=models.SET_NULL,
help_text="If the invoice item is a proration, the plan of the subscription for which the proration was computed.")
subscription = models.ForeignKey("Subscription", null=True, related_name="invoiceitems", on_delete=models.SET_NULL,
help_text="The subscription that this invoice item has been created for, if any.")

def _attach_objects_hook(self, cls, data):
customer = cls._stripe_object_to_customer(target_cls=Customer, data=data)
Expand Down

0 comments on commit 5cc9472

Please sign in to comment.