Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Denis Veselov
committed
Mar 26, 2012
1 parent
34d4750
commit 5d9fb3c
Showing
3 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import sys | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from tinycart.models import CartItem | ||
|
||
|
||
def delete_objects(verbosity=1): | ||
stdout = sys.stdout | ||
count_lost_items = 0 | ||
for item in CartItem.objects.all(): | ||
if item.product is None: | ||
item.delete() | ||
count_lost_items += 1 | ||
if verbosity > 0: | ||
stdout.write('Delete %d cart items\n' % count_lost_items) | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
help = 'Remove lost (deleted) products from cart items.' | ||
|
||
def handle(self, *args, **options): | ||
self.verbosity = int(options.get('verbosity', 1)) | ||
delete_objects(verbosity=self.verbosity) |