Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django中为泛型视图定义一组关系字段_Python_Django_Relationship_Django Models - Fatal编程技术网

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

Python 在Django中为泛型视图定义一组关系字段,python,django,relationship,django-models,Python,Django,Relationship,Django Models,好的,我正在使用一个通用视图来显示我所选的字段,这些字段定义了我的方法字段,它是有效的,但我尝试做的是如下操作,在我的一个自定义字段中,我想检索与我的类“Tareas”中的“idagente”匹配的“Agentes”的名称值 class Tareas(models.Model): fechatarea = models.DateTimeField(null=True, db_column='fechaTarea', blank=True) # Field name made lowerc

好的,我正在使用一个通用视图来显示我所选的字段,这些字段定义了我的方法字段,它是有效的,但我尝试做的是如下操作,在我的一个自定义字段中,我想检索与我的类“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,当我与我的字段建立关系时,我忘记了什么

我回答自己,问题是我没有定义与我的模型相关的名称,我想取他的值,所以最后我得到了:idagente=models.ForeignKey(agents,db\u column='idagente',blank=True,null=True,related\u name=“agents”)