Просмотр исходного кода

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 лет назад
Родитель
Сommit
3e82571dff
1 измененных файлов: 10 добавлений и 6 удалений
  1. 10
    6
      oscar/apps/order/abstract_models.py

+ 10
- 6
oscar/apps/order/abstract_models.py Просмотреть файл

@@ -21,18 +21,21 @@ class AbstractOrder(models.Model):
21 21
 
22 22
     # We track the site that each order is placed within
23 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 30
     user = models.ForeignKey(
29 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 34
     # Billing address is not always required (eg paying by gift card)
33 35
     billing_address = models.ForeignKey(
34 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 40
     # Total price looks like it could be calculated by adding up the
38 41
     # prices of the associated lines, but in some circumstances extra
@@ -56,7 +59,8 @@ class AbstractOrder(models.Model):
56 59
     # address is not mandatory.
57 60
     shipping_address = models.ForeignKey(
58 61
         'order.ShippingAddress', null=True, blank=True,
59
-        verbose_name=_("Shipping Address"))
62
+        verbose_name=_("Shipping Address"),
63
+        on_delete=models.SET_NULL)
60 64
     shipping_method = models.CharField(
61 65
         _("Shipping method"), max_length=128, null=True, blank=True)
62 66
 

Загрузка…
Отмена
Сохранить