美文网首页
Django 代码添加模型字段

Django 代码添加模型字段

作者: 东方灵将 | 来源:发表于2018-04-12 22:17 被阅读0次
    • 定义枚举
    class TcpQuota(SweetEnum):
        RTT_full_sz_avg_a2b = 'RTT_FULL_SZ_AVG_A2B ms'
        throughput_a2b = 'THROUGHPUT_A2B bps'
        throughput_b2a = 'THROUGHPUT_B2A bps'
        RTT_full_sz_min_a2b = 'RTT_FULL_SZ_MIN_A2B ms'
        RTT_full_sz_max_a2b = 'RTT_FULL_SZ_MAX_A2B ms'
        RTT_from_3WHS_a2b = 'RTT_FROM_3WHS_A2B ms'
        RTT_from_3WHS_b2a = 'RTT_FROM_3WHS_B2A ms'
        initial_window_bytes_a2b = 'INITIAL_WINDOW_BYTES_A2B KB'
        initial_window_bytes_b2a = 'INITIAL_WINDOW_BYTES_B2A KB'
        max_win_adv_a2b = 'MAX_WIN_ADV_A2B KB'
        max_win_adv_b2a = 'MAX_WIN_ADV_B2A KB'
        min_win_adv_a2b = 'MIN_WIN_ADV_A2B KB'
        min_win_adv_b2a = 'MIN_WIN_ADV_B2A KB'
        avg_win_adv_a2b = 'AVG_WIN_ADV_A2B KB'
        avg_win_adv_b2a = 'AVG_WIN_ADV_B2A KB'
        duplicate_acks_a2b = 'DUPLICATE_ACKS_A2B'
        duplicate_acks_b2a = 'DUPLICATE_ACKS_B2A'
        triple_dupacks_a2b = 'TRIPLE_DUPACKS_A2B'
        triple_dupacks_b2a = 'TRIPLE_DUPACKS_B2A'
        package_count = 'package_count'
    
    • 定义模型
    class TcpResult(DataResult):
        ip_address = models.CharField(r'IP地址', max_length=30, default=r'0.0.0.0')
        ip_port = models.CharField(r'访问端口,如:433', max_length=7, default=r'0')
    
    • 对TcpResult模型添加指标字段
    for member in TcpQuota:
        TcpResult.add_to_class(member.name,models.DecimalField(member.name, max_digits=20, decimal_places=2, default=0.0))
    

    相关文章

      网友评论

          本文标题:Django 代码添加模型字段

          本文链接:https://www.haomeiwen.com/subject/rrfqkftx.html