zoukankan      html  css  js  c++  java
  • 【django】admin 后台自定义按钮 传参

    class NongYeInfomation(models.Model):
        """
        农业资讯
        """
        title = models.CharField(max_length=255,verbose_name="标题")
        url = models.CharField(max_length=255,verbose_name="路由")
        create_time = models.DateTimeField(auto_now=True,verbose_name="注册时间")
    
        def __str__(self):
            return self.title
    
        def href_route_blank(self):
            path = self.url
    
            button_html = "<a  href='{}' target='_blank'>查看详情{}</a>".format(path,self.pk)
    
            return format_html(button_html)
    
        href_route_blank.short_description = format_html("""<a  href='#' style="position: relative;left: -12px;">新窗口查看</a>""")
    
        def href_route(self):
            path = self.url
    
            # button_html = "<a  href='{}' >查看详情</a>".format(path)
            button_html = "<a  href='/number/{}' >测试数字</a>".format(self.pk)
    
            return format_html(button_html)
    
        href_route.short_description = format_html("""<a  href='#' style="position: relative;left: -12px;">本窗口查看</a>""")
    
    
    
        def data_update(self):
            button_html = ""
    
            return format_html(button_html)
    
        data_update.short_description = format_html(
            """<a  href='nongye/get' style="position: relative;left: -12px;">更新数据</a>""")
    
    
    
        class Meta:
            verbose_name = "农业资讯"
            verbose_name_plural = verbose_name
            db_table = 'NongYeInfomation'






    # 测试获取id
    url(r'number/(?P<ID>.*)$', number.NumberGet.as_view()),


    class NumberGet(APIView):
    def get(self,request,ID):

    message = {}
    try:

    print("ID",ID)

    message['code'] = 200
    message['message'] = "ID是{}".format(ID)
    return JsonResponse(message)
    except Exception as e:
    print(traceback.format_exc())
    msg = traceback.format_exc()
    print(msg)
    message['code'] = 444
    message['message'] = "更新失败"
    return JsonResponse(message)






     

    主攻:Python 数据分析 web 机器学习 图像识别。。 副攻:JAVA WEB 安卓 大数据
  • 相关阅读:
    存储数据的大小端模式
    双链表插入 删除详解
    php_match/preg_match_all 默认有字符串长度限制
    百度编辑器:获取编辑器的内容
    phalcon: update修改数据却变成了insert插入数据
    MySQL按照汉字的拼音排序,mysql汉字排序
    [转载]Eclipse提示No java virtual machine
    lhgdialog: iframe页面里面的,确定,关闭、取消按钮的操作
    js树目录结构
    mysql:恢复mysql表结构
  • 原文地址:https://www.cnblogs.com/wanghong1994/p/13666113.html
Copyright © 2011-2022 走看看