def handle(self, *args, **options):

        if options['devices']:
            devices = Device.objects.filter(is_active=True)

            self.stdout.write("Devices list:\n")
            for device in devices:
                self.stdout.write("(#%s) %s\n" % (device.id, device.name))
            self.stdout.write("\n")
        else:
            collapse_key = options['collapse_key']
            try:
                id = args[0]
                message = args[1]
            except __HOLE__:
                raise CommandError(
                    "Invalid params. You have to put all params: "
                    "python manage.py gcm_messenger <device_id> <msg>")

            try:
                device = Device.objects.get(pk=int(id), is_active=True)
            except Device.DoesNotExist:
                raise CommandError(
                    'Unknown device (id=%s). Check list: '
                    'python manage.py gcm_messenger --devices' % id)
            else:
                result = device.send_message(
                        {'message': message}, collapse_key=collapse_key)

                self.stdout.write("[OK] device #%s (%s): %s\n" %
                                  (id, device.name, result))
dataset/ETHPy150Open bogdal/django-gcm/gcm/management/commands/gcm_messenger.py/Command.handle