from django.core.management import BaseCommand
from podcasts.models import Podcast


class Command(BaseCommand):
    help = 'Initialize podcasts with data from their RSS feeds'

    def handle(self, *args, **kwargs):
        for podcast in Podcast.objects.all():
            podcast.update()

from django.core.management import BaseCommand
from optparse import make_option
from podcasts.models import Podcast


class Command(BaseCommand):
    help = 'Initialize podcasts with data from their RSS feeds'
    option_list = BaseCommand.option_list + (
        make_option(
            '--only-new',
            action='store_true',
            dest='only_new',
            default=False,
            help='Only update new podcasts'
        ),
    )

    def handle(self, *args, **options):
        for podcast in Podcast.objects.all():
            if options['only_new'] and podcast.title != "":
                continue
            podcast.update()

Make it optional to only update metadata of new podcasts
Make it optional to only update metadata of new podcasts

  from django.core.management import BaseCommand
+ from optparse import make_option
  from podcasts.models import Podcast
  
  
  class Command(BaseCommand):
      help = 'Initialize podcasts with data from their RSS feeds'
+     option_list = BaseCommand.option_list + (
+         make_option(
+             '--only-new',
+             action='store_true',
+             dest='only_new',
+             default=False,
+             help='Only update new podcasts'
+         ),
+     )
  
-     def handle(self, *args, **kwargs):
+     def handle(self, *args, **options):
          for podcast in Podcast.objects.all():
+             if options['only_new'] and podcast.title != "":
+                 continue
              podcast.update()
  
Make it optional to only update metadata of new podcasts
## Code Before:
from django.core.management import BaseCommand
from podcasts.models import Podcast


class Command(BaseCommand):
    help = 'Initialize podcasts with data from their RSS feeds'

    def handle(self, *args, **kwargs):
        for podcast in Podcast.objects.all():
            podcast.update()

## Instruction:
Make it optional to only update metadata of new podcasts
## Code After:
from django.core.management import BaseCommand
from optparse import make_option
from podcasts.models import Podcast


class Command(BaseCommand):
    help = 'Initialize podcasts with data from their RSS feeds'
    option_list = BaseCommand.option_list + (
        make_option(
            '--only-new',
            action='store_true',
            dest='only_new',
            default=False,
            help='Only update new podcasts'
        ),
    )

    def handle(self, *args, **options):
        for podcast in Podcast.objects.all():
            if options['only_new'] and podcast.title != "":
                continue
            podcast.update()
