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)

@@ -101,65 +101,193 @@
 m%0A%0A%0A
-def delete_objects(verbosity=1):%0A    stdout = sys.stdout%0A
+class Command(BaseCommand):%0A%0A    help = 'Remove lost (deleted) products from cart items.'%0A%0A    def handle(self, *args, **options):%0A        verbosity = int(options.get('verbosity'))%0A    
     
@@ -307,16 +307,21 @@
 ems = 0%0A
+%0A    
     for 
@@ -352,16 +352,20 @@
 .all():%0A
+    
         
@@ -401,16 +401,20 @@
         
+    
 item.del
@@ -423,32 +423,36 @@
 e()%0A            
+   
+ 
 count_lost_items
@@ -457,20 +457,25 @@
 ms += 1%0A
+%0A  
     
+  
 if verbo
@@ -492,16 +492,24 @@
         
+ 
+   sys.
 stdout.w
@@ -562,244 +562,4 @@
 ms)%0A
-%0A%0Aclass Command(BaseCommand):%0A%0A    help = 'Remove lost (deleted) products from cart items.'%0A%0A    def handle(self, *args, **options):%0A        self.verbosity = int(options.get('verbosity', 1))%0A        delete_objects(verbosity=self.verbosity)%0A

move delete_objects function into handle method