I have these two classes:
class Test(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey(User)
groups = models.ManyToManyField(Group)
class TestSubjectSet(models.Model):
id = models.AutoField(primary_key=True)
test = models.ForeignKey(Test)
subject = models.ManyToManyField(Subject)
The TestSubjectSet form test list shows only string "test object".
First of all, anything is possible. Models can have multiple foreign keys.
Introduction to Django Foreign Key. A foreign key is a process through which the fields of one table can be used in another table flexibly. So, two different tables can be easily linked by means of the foreign key. This linking of the two tables can be easily achieved by means of foreign key processes.
You have to add __unicode__(self)
or __str__(self)
methods in your models class.
http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#django.db.models.Model.unicode
Had the same problem. Adding
def __str__(self):
return self.user
solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With