문제

I have a ForeignKeyField in model number one that displays a __unicode__self.name.

I want to use the same unicode in the second model, but everytime I try to do that it's says I need to encode it, I've been trying to solve this by reading Django docs but I can't figure out how.

Here's the code:

class Viaje(models.Model):
    cliente = models.ForeignKey(Cliente)
    fecha = models.CharField(max_length=244, blank=True)
    origen = models.CharField(max_length=244, blank=True)
    destino = models.CharField(max_length=244, blank=True)
    tracto_numero = models.CharField(max_length=244, blank=True)



    def __unicode__(self):
        return self.cliente
도움이 되었습니까?

해결책

Try this:

def __unicode__(self):
    return unicode(self.cliente)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top