Преглед изворни кода

Ensure deleting a user doesn't delete their orders too

This change ensures that the order model's FKs all use
on_delete=SET_NULL.
master
David Winterbottom пре 12 година
родитељ
комит
3e82571dff
1 измењених фајлова са 10 додато и 6 уклоњено
  1. 10
    6
      oscar/apps/order/abstract_models.py

+ 10
- 6
oscar/apps/order/abstract_models.py Прегледај датотеку

21
 
21
 
22
     # We track the site that each order is placed within
22
     # We track the site that each order is placed within
23
     site = models.ForeignKey('sites.Site', verbose_name=_("Site"))
23
     site = models.ForeignKey('sites.Site', verbose_name=_("Site"))
24
-    basket = models.ForeignKey('basket.Basket', verbose_name=_("Basket"),
25
-                               null=True, blank=True, on_delete=models.SET_NULL)
24
+    basket = models.ForeignKey(
25
+        'basket.Basket', verbose_name=_("Basket"),
26
+        null=True, blank=True, on_delete=models.SET_NULL)
26
 
27
 
27
-    # Orders can be anonymous so we don't always have a customer ID
28
+    # Orders can be placed without the user authenticating so we don't always
29
+    # have a customer ID.
28
     user = models.ForeignKey(
30
     user = models.ForeignKey(
29
         AUTH_USER_MODEL, related_name='orders', null=True, blank=True,
31
         AUTH_USER_MODEL, related_name='orders', null=True, blank=True,
30
-        verbose_name=_("User"))
32
+        verbose_name=_("User"), on_delete=models.SET_NULL)
31
 
33
 
32
     # Billing address is not always required (eg paying by gift card)
34
     # Billing address is not always required (eg paying by gift card)
33
     billing_address = models.ForeignKey(
35
     billing_address = models.ForeignKey(
34
         'order.BillingAddress', null=True, blank=True,
36
         'order.BillingAddress', null=True, blank=True,
35
-        verbose_name=_("Billing Address"))
37
+        verbose_name=_("Billing Address"),
38
+        on_delete=models.SET_NULL)
36
 
39
 
37
     # Total price looks like it could be calculated by adding up the
40
     # Total price looks like it could be calculated by adding up the
38
     # prices of the associated lines, but in some circumstances extra
41
     # prices of the associated lines, but in some circumstances extra
56
     # address is not mandatory.
59
     # address is not mandatory.
57
     shipping_address = models.ForeignKey(
60
     shipping_address = models.ForeignKey(
58
         'order.ShippingAddress', null=True, blank=True,
61
         'order.ShippingAddress', null=True, blank=True,
59
-        verbose_name=_("Shipping Address"))
62
+        verbose_name=_("Shipping Address"),
63
+        on_delete=models.SET_NULL)
60
     shipping_method = models.CharField(
64
     shipping_method = models.CharField(
61
         _("Shipping method"), max_length=128, null=True, blank=True)
65
         _("Shipping method"), max_length=128, null=True, blank=True)
62
 
66
 

Loading…
Откажи
Сачувај