related field in django

0

When I relate two tables for a common field , in the administration system, it does not return the value of the related field in the table where the value should appear, example ..

class t_tlicencia(models.Model):
    codtlicencia = models.CharField('Cod.Licencia',max_length=2,null=False, blank=False, unique=True, primary_key=True)
    nombre       = models.CharField('Tipo de licencia:',max_length=50, blank=False)

To sort the table

class Meta:
    ordering = ('codtlicencia',)
    default_related_name = "codtlicencia"

Function to return parameters of the class

def datoslicencia(self):
    cadena = '{0},{1}'
    return cadena.Format(self.codtlicencia, self.nombre)

def __str__(self):
    return self.datoslicencia()

class t_personal(models.Model):
    acceso       = models.ForeignKey(settings.AUTH_USER_MODEL, help_text="Nombre del Operador")
    noreg        = models.CharField('No.Registro:',max_length=11,null=False, blank=False, unique=True, primary_key=True, help_text="Escribir el numero de registro del chofer")

    nombre       = models.CharField('Nombre:',max_length=20, blank=False)
    apel1        = models.CharField('1re Apellido',max_length=20, blank=False)
    apel2        = models.CharField('2do Apellido',max_length=20, blank=False)
    codtlicencia = models.ForeignKey(t_tlicencia)

To sort the table

class Meta:
    ordering = ('noreg',)
    default_related_name = "codtlicencia"   

Function to return parameters of the class

def datospersonal(self):
    cadena='{0},{1},{2},{3},{4},{5}'
    now = timezone. now()
    return cadena.Format(self.noreg, self.nombre, self.apel1, 
                        self.apel2, self.codtlicencia)

def __str__(self):
    return self.datospersonal()

In the administration system it returns the record without problem, but the related field codtlicencia, in the table t_personal in the field codtlicencia returns me as value the following < em> t_personal object and what I want is to show the value of the field in the table t_tlicencia.codtlicencia

    
asked by Barbaro Elisor Hernández 01.08.2018 в 18:19
source

0 answers