Thanks for checking this out.
Silly doubt of mine:
I have the following models defined in Django:
class School(models.Model):
name = models.CharField(max_length=256)
principal = models.CharField(max_length=256)
location = models.CharField(max_length=256)
def __str__(self):
return self.name
class Student(models.Model):
name = models.CharField(max_length=256)
age = models.PositiveIntegerField() # positive integer only accepts positives
school = models.ForeignKey("School", related_name='students', on_delete=models.CASCADE)
def __str__(self):
return self.name
My question is: How does Django knows to pick the School.name field as a match for the foreign key school? As when I check on the Admin page and add a student, I can select the name of the school (as the foreign key). Name: Age: School = (drop down with the name of the schools)
Is it the order of the elements or something else?
Thanks again!