在Djang中为泛型视图定义一组关系字段

2024-10-03 11:15:50 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,我用一个泛型视图来显示我选择的字段定义我的方法字段,它可以工作,但我尝试做的是如下操作,在我的一个自定义字段中,我想检索与类“Tareas”中的“idagente”匹配的“Agentes”的名称值

class Tareas(models.Model):
    fechatarea = models.DateTimeField(null=True, db_column='fechaTarea', blank=True) # Field name made lowercase.
    horainicio = models.DateTimeField(null=True, db_column='horaInicio', blank=True) # Field name made lowercase.
    horafin = models.DateTimeField(null=True, db_column='horaFin', blank=True) # Field name made lowercase.
    observaciones = models.TextField(blank=True)
    unidades = models.BigIntegerField(null=True, blank=True)
    validar = models.IntegerField()
    idtipotarea = models.ForeignKey(Tipotarea, db_column='idtipotarea')
    idtarea = models.IntegerField(primary_key=True, db_column='idTarea')
    idagente = models.ForeignKey(Agentes, db_column='idagente',blank=True, null=True)
    def __fields__(self,profile):        
        fields=[]
        fields.append( ('idagente'), _('Tipo de Agente')) )
        fields.append( ('fechatarea', _('Fecha de Tarea') ) )
        fields.append( ('horainicio', _('Inicio') ) )
        fields.append( ('horafin', _('Fin') ) )
        fields.append( ('unidades', _('Unidades') ) )    

        return fields

在我的模型类por agents中,我定义了一个unicode方法,它返回我的雇员的名字,但总是打印他的id,当我与我的领域建立关系时,我忘记了什么?你知道吗


Tags: nametruefieldfieldsdb定义modelscolumn