Created
September 19, 2017 14:17
-
-
Save clintonb/9c13b56da1368186bc65edebced709c4 to your computer and use it in GitHub Desktop.
Delete ecommerce history data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import pytz | |
from oscar.core.loading import get_model | |
from ecommerce.courses.models import Course | |
from ecommerce.invoice.models import Invoice | |
Order = get_model('order', 'Order') | |
OrderLine = get_model('order', 'Line') | |
Product = get_model('catalogue', 'Product') | |
ProductAttributeValue = get_model('catalogue', 'ProductAttributeValue') | |
Refund = get_model('refund', 'Refund') | |
RefundLine = get_model('refund', 'RefundLine') | |
StockRecord = get_model('partner', 'StockRecord') | |
cutoff = datetime.datetime(2017, 1, 1, 0, 0, 0, 0, pytz.UTC) | |
models = (Order, OrderLine, Refund, RefundLine, ProductAttributeValue, Product, StockRecord, Course, Invoice,) | |
for model in models: | |
print('{}: {}'.format(model.__name__, model.history.filter(history_date__lt=cutoff).count())) | |
# for model in models: | |
# model.history.filter(history_date__lt=cutoff).delete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment