django model字段获取id字段的默认值

时间:2018-08-17 11:37:32

标签: django leaflet geoserver

大家好,我想从geoserver中显示地图中某个图层的标签,但是geoserver不允许我将id字段显示为标签。我创建了一个新值no_man,并希望此字段自动获取ID的值。如果有一种显示id标签的方法,我将删除no_man,否则我想用id的值填充此字段。

models.py

class ww_manholes(models.Model):
    id = models.BigIntegerField(primary_key=True)
    no_man = models.BigIntegerField()
    l_ass_obj = models.BigIntegerField()
    l_field_re = models.BigIntegerField()
    street = models.BigIntegerField()
    zip_code = models.BigIntegerField()
    regio_code = models.BigIntegerField()
    owner = models.BigIntegerField()
    ww_type = models.BigIntegerField()
    accuracy = models.BigIntegerField()
    x = models.FloatField()
    y = models.FloatField()
    x_ge = models.FloatField()
    y_ge = models.FloatField()
    z = models.FloatField()
    invert_el = models.FloatField()
    inv_start = models.FloatField()
    inv_end = models.FloatField()
    depth = models.FloatField()
    depth_star = models.FloatField()
    depth_end = models.FloatField()
    material = models.BigIntegerField()
    lining = models.BigIntegerField()
    coating = models.BigIntegerField()
    contractor = models.BigIntegerField()
    const_year = models.BigIntegerField()
    diam_nom = models.BigIntegerField()
    diam_inner = models.BigIntegerField()
    joint_type = models.BigIntegerField()
    cover_dim = models.BigIntegerField()
    cover_mat = models.BigIntegerField()
    access = models.BigIntegerField()
    rough_coef = models.FloatField()
    slope = models.FloatField()
    type = models.BigIntegerField()
    sc_condit = models.BigIntegerField()
    sc_perform = models.BigIntegerField()
    sc_fail_pr = models.BigIntegerField()
    sc_fin_imp = models.BigIntegerField()
    sc_soc_imp = models.BigIntegerField()
    sc_leg_imp = models.BigIntegerField()
    sc_env_imp = models.BigIntegerField()
    sc_red_sl = models.BigIntegerField()
    sc_imp_ph = models.BigIntegerField()
    sc_imp_rep = models.BigIntegerField()
    sc_rep_cos = models.BigIntegerField()
    sc_co_fail = models.BigIntegerField()
    l_picture = models.CharField(max_length=254)
    l_drawing = models.CharField(max_length=254)
    key_om = models.FloatField()
    comments = models.CharField(max_length=254)
    geom = models.MultiPointField(srid=7392)

    def __unicode__(self):
        return self.id

1 个答案:

答案 0 :(得分:0)

将其添加到模型中可以最大程度地解决您的问题。

C2679   binary '<<': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)  

更新:按要求

不推荐,但这是使用Django signals复制字段值的方法:

def __str__(self):
    return self.id