[Answer]-Showing different name of ForeignKey in form

1👍

Define it inside your model class as follows:

def __unicode__(self):
    return self.first_name + self.last_name

0👍

0👍

Define the default string representation on the target model:

class Trida(models.Model):
    název=models.CharField(max_length=20)
    tridni_ucitel=models.ForeignKey(Ucitel, blank=True, null=True)
    predmety=models.ForeignKey(Predmety, blank=True, null=True)

class Ucitel(models.Model):
    firstname=models.CharField(max_length=20)
    lastname=models.CharField(max_length=20)
    ...

    def __unicode__(self):
        return u'%s %s' % (self.firstname, self.lastname)

If you are using Python 3, use __str__() instead of __unicode__().

This is covered in the first page of the Django Tutorial: https://docs.djangoproject.com/en/dev/intro/tutorial01/

👤StvnW

Leave a comment