views:

137

answers:

2

Hello, trying to understand how custom admin commands work, I have my project named "mailing" and app inside named "msystem", I have written this retrieve.py to the mailing/msystem/management/commands/ folder and I have pasted an empty init.py both to the management and cpmmands folders.

from django.core.management.base import BaseCommand
from mailing.msystem.models import Alarm

class Command(BaseCommand):
    help = "Displays data"
    def handle(self, *args, **options):
      x = Alarm.objects.all()
      for i in x:
       print i.name

I am weirdly getting "indention" error for handle function when I try "python manage.py retrieve" however it looks fine to me, can you suggest me what to do or point me the problem

Thanks

+2  A: 

If you're getting an "indentation error" and everything looks aligned, this usually suggests that you're mixing tabs and spaces.

I suggest ensuring that your module is only using spaces.

SmileyChris
+1 beat me to it :)
Van Gale
Thanks for the +1, but verbosity over speed for the best answer ;)
SmileyChris
+4  A: 

Your indentation needs to be consistent through the entire file, which it isn't in the snippet you posted above.

The "help = " line is indented four spaces after "class" but then the "x =" line is indented many more than four.

Maybe you are mixing spaces and tabs and thus have two tabs before "x ="?

Your code should look like this:

from django.core.management.base import BaseCommand
from mailing.msystem.models import Alarm

class Command(BaseCommand):
    help = "Displays data"
    def handle(self, *args, **options):
        x = Alarm.objects.all()
        for i in x:
            print i.name
Van Gale