Skip to content

Commit

Permalink
Change type and name of basket field on AbstractOrder
Browse files Browse the repository at this point in the history
It used to be a PositiveIntegerField containing the primary key of the
basket. This was a minor design deficiency; a nullable ForeignKey field
seems like the correct way to model that relation.
It's also been renamed from basket_id to basket to reflect the change.

Migrations unfortunately are non-trivial:
* 0019 adds the new ForeignKey field, but called basket_alt
* 0020 migrates data from the old field to the new field
* 0021 drops the now unnecessary field basket_id
* 0022 renames the basket_alt field to basket

The additional step with naming it basket_alt is necessary because of a
column name conflict. Django will pick a column name of 'basket_id' for
a ForeignKey field named 'basket', which is the same column name the
old PositiveIntegerField had.
  • Loading branch information
maiksprenger committed Jan 9, 2014
1 parent 8af9400 commit 1bbe821
Show file tree
Hide file tree
Showing 7 changed files with 1,965 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/source/releases/v0.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Minor changes
Backwards incompatible changes in 0.7
=====================================

* Order.basket_id was a PositiveIntegerField containing the primary key of the
associated basket. It's been refactored to be a nullable ForeignKeyField and
is now called basket.

Removal of features deprecated in 0.6
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions oscar/apps/order/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class AbstractOrder(models.Model):

# We track the site that each order is placed within
site = models.ForeignKey('sites.Site', verbose_name=_("Site"))
basket_id = models.PositiveIntegerField(
_("Basket ID"), null=True, blank=True)
basket = models.ForeignKey('basket.Basket', verbose_name=_("Basket"),
null=True, blank=True, on_delete=models.SET_NULL)

# Orders can be anonymous so we don't always have a customer ID
user = models.ForeignKey(
Expand Down
486 changes: 486 additions & 0 deletions oscar/apps/order/migrations/0019_auto__add_field_order_basket_alt.py

Large diffs are not rendered by default.

508 changes: 508 additions & 0 deletions oscar/apps/order/migrations/0020_convert_basket_ids.py

Large diffs are not rendered by default.

485 changes: 485 additions & 0 deletions oscar/apps/order/migrations/0021_auto__del_field_order_basket_id.py

Large diffs are not rendered by default.

479 changes: 479 additions & 0 deletions oscar/apps/order/migrations/0022_rename_basket_field.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion oscar/apps/order/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def create_order_model(self, user, basket, shipping_address,
"""
Creates an order model.
"""
order_data = {'basket_id': basket.id,
order_data = {'basket': basket,
'number': order_number,
'site': Site._default_manager.get_current(),
'currency': total.currency,
Expand Down

0 comments on commit 1bbe821

Please sign in to comment.