Skip to content

Commit

Permalink
add delete_lost_cartitems command
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Veselov committed Mar 26, 2012
1 parent 34d4750 commit 5d9fb3c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Empty file added tinycart/management/__init__.py
Empty file.
Empty file.
25 changes: 25 additions & 0 deletions tinycart/management/commands/delete_lost_cartitems.py
@@ -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)

0 comments on commit 5d9fb3c

Please sign in to comment.