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)