zoukankan      html  css  js  c++  java
  • Django 自定义扩展命令

    import datetime
    import logger
    from django.conf import settings
    from django.db.models import Q
    from django.core.management.base import BaseCommand
    from xxx.models import User
    from xxx.tools import message_client
    
    
    MSEEAGE = u"Hello %s , Welcome to XXX."
    
    
    class Command(BaseCommand):
        def handle(self, *args, **kwargs):
            print args
            print kwargs
            send_level = args[0].split(',')
            td = datetime.datetime.now()
            td0 = datetime.datetime(dt.year, dt.month, dt.day)
            reg_time = now_day_value + datetime.timedelta(days=-4)
            query_condition = Q(active='1') & Q(status='y') & Q(registe_time__gte=reg_time) & Q(level__in=send_level)
            user_list = User.objects.filter(query_condition)
            for u in user_list:
                if u.phone:
                    try:
                        msg = MSEEAGE % u.name
                        message_client.send_message(phone_number=eachUser.phone_no, content=msg.encode("gbk"))
                    except Exception, e:
                        logger.error(e.message)
                        logger.error("failed send to %s" % str(u.phone))

    比如我们的python 文件名是:batch_send_msg.py


    那么我们调用的方法是:python manage.py batch_send_msg 1,2  ;

    给等级为1和2的用户发送消息。

    和Django 启动的命令(python manage.py runserver 0.0.0.0:8001)使用方式一样

  • 相关阅读:
    单例模式
    pandas to_html
    restful
    numpy版本查看以及升降
    视频下载
    转载:caffe中的Reshape层
    caffe编译报错解决
    python 版Faster Rcnn
    转载:动态规划以及路径记录
    TensorFlow设置GPU占用量
  • 原文地址:https://www.cnblogs.com/huaizhi/p/8398819.html
Copyright © 2011-2022 走看看